tags:

views:

16

answers:

1

I've got a list of products in an admin section of my website. I have the product title and then an icon for delete and an icon for set visible/set invisible. I have both icons wrapped in their own form elements so they fire seperate Actions. I now one to add some checkboxes to each line so I can do a bulk delete. Following this:

http://stackoverflow.com/questions/220020/how-to-handle-checkboxes-in-asp-net-mvc-forms

I'd need to wrap the whole list in a form tag to return the checkbox values, but then I have the icons on each row wrapped in form tags. I'm not sure what to do or how to handle this so it all works. How can I maintain the line form tags but still get bulk update functionality?

A: 

It's probably going to require some JavaScript. I would create a form outside of the table with a hidden element. When a box is checked, update the hidden element to contain a comma-separated list of all the IDs for rows that have the checkboxes checked (this would be pretty straightforward with jQuery). When that form is submitted, parse the values of the hidden element and delete accordingly.

Another option is to wrap the whole thing in one form and make the names of the delete buttons unique, then check for that when the form is submitted. When doing a bulk delete, you'll have all the checkbox values submitted like normal and you'll know it's a bulk delete based on which button they pressed to submit the form.

John Sheehan
I opted to have an id on the checkboxes. when the bulk operation was clicked it grabbed all the selected checkboxes and read in their Id's. This enabled me to keep the form tags around each row. The bulk operation would then fire an ajax call. It'd be nice to get an idea on how to get this working without javascript (for future reference) but since I'm the client I know for sure JS will be enabled.
lloydphillips
The way to do this without JS is my second proposal. One form, pull out the values you need based on the button pushed.
John Sheehan