TienKenji
TienKenji

Reputation: 71

Using Checkbox submit form in asp.net mvc

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

Upvotes: 1

Views: 12968

Answers (1)

Kaf
Kaf

Reputation: 33839

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();"})

Upvotes: 5

Related Questions