15

The best advice I found for editing a variable-length list of items was written for ASP.Net MVC 2 in 2008.

http://blog.stevensanderson.com/2008/12/22/editing-a-variable-length-list-of-items-in-aspnet-mvc/

Is that approach still the best one for ASP.Net MVC 4, or is there a newer solution that is either standardized, or more elegant?

Display Name
  • 4,672
  • 1
  • 33
  • 43
Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • I think people are doing this kind of thing via Ajax when possible. Not only is it a lot simpler from a code perspective, it offers a better user experience. – Jon Galloway Jul 30 '12 at 18:50
  • @JonGalloway can you link to some example? – Display Name Sep 12 '12 at 19:22
  • It's not too bad if you don't want to have the list re-arrangeable. You can do it completely on the client-side using knockoutjs for example or go for a mixed approached by pulling a partial view through ajax for each new item. – Ivan Zlatev Sep 14 '12 at 13:32
  • @IvanZlatev I am following your postings @ ivanz.com. However, last article on the topic (for MVC3) was released about a year ago. Do you happen to work on MVC 4 version (or will it be the same as MVC 3). Its just pitty that such basic functionality is not built into the framework and we have to use so many plugins and learn so many new techs to do quite basic stuff, that any more or less serious web site is doing. Thanks – Display Name Sep 24 '12 at 20:22

1 Answers1

7

Take a look at http://knockoutjs.com/ it's a JavaScript framework that relies on the MVVM pattern. Basically you can data-bind array models to your HTML and then post them back as JSON arrays to your controller. One great side-effect is that it helps to make your controllers more unit-test friendly (because your controllers mainly return JSON).

There's a great video about knockout at http://channel9.msdn.com/Events/MIX/MIX11/FRM08

Basically what you want to look at is observable arrays. http://knockoutjs.com/documentation/observableArrays.html

I would also highly recommend you watch the 20 minute video introduction on knockout.js. Even though it's an older video it gives you a good idea of how it works, it helped me a lot. http://channel9.msdn.com/Events/MIX/MIX11/FRM08

You can also use AngularJS http://angularjs.org/ which is the same concept (MVVM), it is put out by google. There are a lot of differences between the two but the most major one (I noticed atleast) is in angular there is more reliance on templating, in a lot of respects it gives it more power.

Between the two I think knockout is easier to get up and running but you have more options with AngularJS.

nerdybeardo
  • 4,655
  • 23
  • 32