Is there any way to pass the checkbox values to the controller on checking from a list of checkbox without using any submit button or any jquery Ajax? I just want to use only asp.net mvc property.
2 Answers
As user1576559 sad in comment:
I want to submit the form when I'll check or uncheck any of the checkboxs without using any jquery or ajax
Here it is:
@using (Html.BeginForm("Update", "Home"))
{
<p>Checkboxes:</p>
@Html.CheckBox("chk1", new { onchange = "this.form.submit()" }); <br/>
@Html.CheckBox("chk2", new { onchange = "this.form.submit()" }); <br />
@Html.CheckBox("chk3", new { onchange = "this.form.submit()" }); <br />
}
Comments
As per my understanding, you need to use @Html.CheckboxFor(m=>m.PropertyName) when you send the page to server then you get the updated checkbox status.
3 Comments
user1576559
Yes..I know that.But it's only possible when I submit the form by clicking submit button.But my requirement is little a bit different.I want to submit the form when I'll check or uncheck any of the checkboxs without using any jquery or ajax.
Amit
@user1576559 without sending any request how the controller know that you have changed the check box status
Carl
Do you just want to submit the form automatically when the checkbox changes? In which case you can just use an event handler e.g.:
$("#yourCheckboxID").click(function(){$('#yourFormID').submit();}); or the JavaScript equivalent. You can't do this without JavaScript, but it will submit the form normally, not as an Ajax call.