1

How can i update a method in controller if a checkbox is checked? see image below https://i.sstatic.net/5RmbK.jpg

>[HttpPost] 
>public ActionResult Update(int id) 
>{
> //code update status in db
> }

1 Answer 1

5

Try this (Razor syntax):

//for a checkbox 
@Html.CheckBox("chkName",false, new {onclick="this.form.submit();"})

//if using strongly typed model property
@Html.CheckBoxFor(model=> model.chkName, new {onclick="this.form.submit();"})
Sign up to request clarification or add additional context in comments.

2 Comments

i had done, thank you for reply<br/> @using (Html.BeginForm("Update", "Admin", new { id = item.ID }, FormMethod.Post)) { @Html.AntiForgeryToken() @Html.CheckBox("CkbStatus", item.Status ? true : false, new { onclick="this.form.submit();"}) }
Note the use of Checkbox or CheckboxFor over Editor or EditorFor. Simply adding html attributes for onclick="this.form.submit();" isn't enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.