Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to handle repeating forms in MVC?

Tags:

The best public example that I can think of off the top of my head would be the amazon shopping cart. Where you have a page that displays multiple distinct records that can have multiple distinct fields updated.

I can't put each one in a form tag because the user may modify more than one record and then submit.

I can't just update all the records that I get back because:
1. Performance
2. Auditing
3. If someone changed the record that the user 'didn't change' when they were viewing the page and then the user submits those changes would be overwritten.

So how to best handle getting the data back and then getting which records where changed out of that?

Is that clear?

like image 804
Andrew Burns Avatar asked Feb 05 '09 21:02

Andrew Burns


1 Answers

Use binding! Don't be iterating the form collection in your actions.

Steve Sanderson wrote a blog post about how to do it. I wrote a blog post on how to do it with MvcContrib.FluentHtml. Both posts are very detailed and include downloadable code.

like image 113
Tim Scott Avatar answered Sep 21 '22 21:09

Tim Scott