I'm trying to figure out the right way to do something in MVC that won't be difficult in WebForms, and I hope someone can point me in the right direction.
Basically, I am showing a data table, and the user should be able to select zero or more rows. When they click the submit button, I want my controller to know which rows were selected, as this will affect other data on the screen.
My view is as follows:
<form action="/Summary/Index" method="post"> <table> <thead> <tr> <th></th> <th>Name</th> <th>Age</th> </tr> </thead> <tbody> <% foreach (Person p in Model) { %> <tr> <td> <input type="checkbox" name="" /> </td> <td><%= p.Name %></td> <td><%= p.Age %></td> </tr> <% } %> </tbody> </table> <input type="submit" value="Update" /> </form>
So, when the submit button is clicked, the form will be sent to the current URL. Please note that the "Man" model is just a ViewModel, so I can add any necessary interface properties if necessary. Should I add the "Selected" property for Person and make my controller take a list / array of Person and check each selected property?
Please note that I need a solution that will work without JavaScript, and I donβt want my controller to worry about how the checkbox values ββare retrieved - I am happy to write my own ModelBinder, if necessary.
Can someone give me an idea how to do this?
Thanks a lot, Simon.
Simon source share