user1576559
user1576559

Reputation: 79

Post checkbox values using MVC property

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.

Upvotes: 0

Views: 436

Answers (2)

aleha_84
aleha_84

Reputation: 8539

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 />
}

Upvotes: 1

Amit
Amit

Reputation: 15387

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.

Upvotes: 0

Related Questions