Is there a reason why my Html.CheckBox() View control is returning null up to the Controller ?
Can’t seem to figure this one out and would appreciate any help !
View:
@{ Html.BeginForm("ActionName", "ControllerName", FormMethod.Get); }
Enter Text: @Html.TextBox("Code", string.Empty, new { id = "Code" })
<input type="submit" value="GO" />
<span style="padding-left:20px; font-size:14px" >@Html.CheckBox("exactMatch", false, new { id = "textmatches" })
 Text exact match</span>
@{ Html.EndForm(); }
Controller that gets called upon submitting the form:
public ActionResult ActionName(string code,bool boxChecked)
{
return View(ServiceCallGoesHere(code.Trim(),boxChecked));
}
I can’t figure out why in the world is my checkbox status not being passed to the controller. Why is boxChecked parameter in the controller always = null ? How can I resolve this problem ?
Thank you in advance !
As far as I know when the view post back the data MVC framework uses the id of form controls to map them with the parameters of an action of your controller.Maybe that’s why you can’t get the right data