tags:

views:

191

answers:

1

I use the following HTML helper to generate check box:

<%= Html.CheckBox("DeluxeFeature")%>

Now I want to access the value of this checkbox in my controller. How should I do this? I am not going to use the method parameter name, for the reason that there are a lot of checkboxes and putting all of them in the parameter will clutter the method.

I try to use

Request.Form["DeluxeFeature"]

But the behavior is very weird; if the checkbox is not ticked, then the Request.Form["DeluxeFeature"] returns "false", which is expected. But if the checkbox is ticked, then it retruns "true, false".

Very weird, isn't it?

+2  A: 

This thread on the asp.net forums explains the behavior - there's even a comment by Phil Haack from the ASP.NET MVC project team (bonus!!).

So the best way to handle it if you're not using the helpers/model binders as posted by levib seems to be

Request.Form.GetValues("DeluxeFeature")[0]
Luke Sampson