I have some html checkboxes on a page and I need to verify that they have been check in the postback event for the page.
The data for these checkboxes is not stored in a database, they just have to be checked before the use can go to the next page.
How do i verify that they are checked? I don’t see them in the Request.Form.AllKeys collection
<input id='terms_eligibility' type='checkbox' />
<input id='terms_accurate' type='checkbox' />
<input id='terms_score_release' type='checkbox' />
EDIT
Here’s what I ended up doing
View
@Html.CheckBox("terms_eligibility")
Controller
string eligibility = Request.Form.GetValues("terms_eligibility")[0];
When a HTML checkbox is not checked then its value is not sent back to the webserver.
MVC solves this problem by adding an
<input type="hidden" />for each checkbox which ensures that a value is always sent, so it can detect if a checkbox was checked or not.To use these hidden inputs you must use the
Html.CheckBoxorHtml.CheckBoxForhelper methods.Anyway, the HTML you posted doesn’t have any
name=""attributes. HTML inputs must have a name attribute. They don’t use theidattribute for form field keys.