0

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?

Fabian Steeg
  • 44,988
  • 7
  • 85
  • 112
Al Katawazi
  • 7,192
  • 6
  • 26
  • 39
  • What does the generated HTML look like? – Craig Stuntz Feb 06 '09 at 16:26
  • Debating closing as dupe http://stackoverflow.com/questions/220020/how-to-handle-checkboxes-in-asp-net-mvc-forms –  Feb 06 '09 at 16:29
  • I don't think it's the same question. You are asking about the value attribute; he is asking about the name attribute. (I think.) – Craig Stuntz Feb 06 '09 at 16:36
  • This is a bug with the MVC Framework RC1. Form.Keys should be populating with my checkboxes but they aren't. This worked previously in the Beta so I have no idea what is going on. – Al Katawazi Feb 07 '09 at 17:14

1 Answers1

2

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?

Levi
  • 32,628
  • 3
  • 87
  • 88