MVC 4 - More Elegant way to Edit Variable-Length List of Items?

狂风中的少年 提交于 2019-12-02 20:43:16

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!