I am using
@Html.CheckBoxFor(model => model.AllowOrder, new { id = "allowOrder"})
Now I want to pass its value (whether checked or unchecked) to the controller. I am using html.BeginForm
for posting back the data to controller. Every time I am getting its value as null in action method. Action method has below sample code.
public ActionResult index(bool isChecked)
{
// code here
}
isChecked
property is passed in as null always. Any help please. TIA.
2
Answers
If you don’t want to return to controller whole data model, but only one value then see code below:
Using the
onclick()
to trace the checkbox state:View:
Controller:
This way when you submit the form, the entire model will be posted back and you can receive it in the controller method