Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Please help me out in knowing the selected checkboxes in the webgrid in MVC3.

Thanks in Advance
Pavan
Posted

1. Ensure that your webgrid is wrapped inside a form.

HTML
@using (Html.BeginForm("Assign","Home"))
  {
  }


In the webgrid columns add a column with check box as follows which I think already you have.


HTML
grid.Column(header: "Assign?", format: @<text><input class="check-box"  id="assignChkBx"name="assignChkBx" type="checkbox" value="@item.Id"/></text>)



2. At Controller Retrieve objects that are checked using id values as follows::

C#
[HttpPost]
        public ActionResult Assign(FormCollection form)
        {
            var ch = form.GetValues("assignChkBx");
            foreach (var id in ch)
            {
              //...Get object using id
              //...Call your method
            }
            return View();
        }
 
Share this answer
 
v2
Comments
LeonardoMiller 23-Mar-16 21:44pm    
Works like a charm!!! :))
midhunkumaralluru 31-Aug-17 1:10am    
I tried the approach in VS2017 but get as null.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900