Checkbox in asp.net mvc
I have two options
One
<%= Html.CheckBox("postType", false, new { @id = item.int_PostTypeId.ToString() })%>
Second
<input type="checkbox" name="postType" value="<%= item.int_PostTypeId.ToString() %>
1st question: what is the difference between the two methods for declaring flags.
The second question: and how can we get the value of the checked flag?
Use Html.Checkbox (or even better CheckBoxFor, in MVC2) if you use model binding. It will handle the checkbox transparently for you, and you will read the boolean in your model. This will do something more complicated than the checkbox (to avoid the problem that arises from the fact that the unchecked checkbox is not passed at all to POST).
, , FormCollection: Html.Checkbox, - "" ( , (, "true", "false" ). , , .