I have an MVC3 C#.Net web app. I have a requirement to display a list of check boxes (either in a drop down or a List Box) dynamically based on a table in our db. The table can contain 1:500 entries. I then need to pass the selected check boxes to the Controller in order to perform an action on each selection. Any ideas on an implementation?
Share
There are many ways to go about this but here is a general demo.
You can pass a list of the checkbox values and descriptions either on the
Model(as this example does),ViewData[""]dictionary orViewBag(MVC3+).Then in your view loop through them and add them to your form using the name=”chxBxGroupName” to group them.
Now create a controller action to post to that takes a
Listof the value type (in this exampleint) with the parameter naming matching the name=”chxBxGroupName“.It will post a list of checked values.
The post page will just print out: