Al Katawazi
Al Katawazi

Reputation: 7242

Checkbox Array in MVC Framework

Ok not sure what is going on with these checkboxes in the MVC Framework RC1 but here is what I got. I am creating checkboxes using a foreach loop on the view but when I try to access them using the Request.Form.Keys in the controller I get nothing back. My question is how is Request.Form.Keys populated? I know the checkbox inputs are on the form but I get nothing in terms of keys back.

Here are code samples

<% foreach (var item in Model){ %>
<tr align="center">
<% if (item.IsActive){ %>
<td><%= Html.CheckBox("session." + item.SessionID, item.SessionID)%></td>
<% } else { %>
<td><b>Closed</b></td>
<% } %>

And the controller uses this

foreach (String key in Request.Form.Keys)
{
    if (key.StartsWith("Session."))
    {
         //Do Something
     }
}

Any Ideas?

Upvotes: 0

Views: 1299

Answers (1)

Levi
Levi

Reputation: 32818

String.StartsWith() is case-sensitive by default. You are rendering the name "session.{stuff}" to the form, but you are checking for "Session.{stuff}" (note the different capitalization). Does making these consistent solve your problem?

Upvotes: 2

Related Questions