MVC 4 - 更优雅的方式来编辑可变长度的项目列表?

时间:2021-01-15 20:19:11

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

我发现编辑可变长度项目列表的最佳建议是在2008年为ASP.Net MVC 2编写的。

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

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?

这种方法仍然是ASP.Net MVC 4的最佳方法,还是有更新的标准化或更优雅的解决方案?

1 个解决方案

#1


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).

看看http://knockoutjs.com/这是一个依赖于MVVM模式的JavaScript框架。基本上,您可以将数组绑定到HTML,然后将它们作为JSON数组发布回控制器。一个很好的副作用是它有助于使您的控制器更加单元测试友好(因为您的控制器主要返回JSON)。

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

有关于淘汰赛的精彩视频,请访问http://channel9.msdn.com/Events/MIX/MIX11/FRM08

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

基本上你想要看的是可观察的数组。 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

我还强烈建议你观看关于knockout.js的20分钟视频介绍。即使它是一个较旧的视频,它让你很好地了解它是如何工作的,它对我帮助很大。 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.

您也可以使用AngularJS http://angularjs.org/这是相同的概念(MVVM),它是谷歌推出的。两者之间存在很多差异,但最重要的一个(我注意到至少)是有角度的,更多地依赖于模板,在很多方面它赋予它更多的力量。

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

在两者之间,我认为淘汰赛更容易起床和运行,但你有更多的AngularJS选项。

#1


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).

看看http://knockoutjs.com/这是一个依赖于MVVM模式的JavaScript框架。基本上,您可以将数组绑定到HTML,然后将它们作为JSON数组发布回控制器。一个很好的副作用是它有助于使您的控制器更加单元测试友好(因为您的控制器主要返回JSON)。

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

有关于淘汰赛的精彩视频,请访问http://channel9.msdn.com/Events/MIX/MIX11/FRM08

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

基本上你想要看的是可观察的数组。 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

我还强烈建议你观看关于knockout.js的20分钟视频介绍。即使它是一个较旧的视频,它让你很好地了解它是如何工作的,它对我帮助很大。 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.

您也可以使用AngularJS http://angularjs.org/这是相同的概念(MVVM),它是谷歌推出的。两者之间存在很多差异,但最重要的一个(我注意到至少)是有角度的,更多地依赖于模板,在很多方面它赋予它更多的力量。

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

在两者之间,我认为淘汰赛更容易起床和运行,但你有更多的AngularJS选项。