如何绑定模式,以列表<视图模型&GT ;? [英] How to model bind to a List<ViewModel>?

查看:114
本文介绍了如何绑定模式,以列表<视图模型&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图完成这样的事情。我觉得这是可能的,如果不是很可能在MVC框架的疏忽?

I'm trying to accomplish something like this. I feel like it's possible, and if not probably an oversight in the MVC framework?

查看:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<List<MyViewModel>>" %>
...
<% foreach (MyViewModel vm in Model) {
    Html.RenderPartial("MyViewModelPartial", vm);
} %>

是一个可编辑形式的局部视图,强类型的单个MyViewModel,并使用在MyViewModel类DataAnnotations验证

The partial view being an editable form, strongly typed to a single MyViewModel, and use the DataAnnotations on the MyViewModel class to validate

控制器:

public ActionResult FooController(List<MyViewModel> vml)
{ 
   ...
}

这可能吗?这似乎是建立在MVC网格/表结构(每个局部视图是一个表行)最合乎逻辑的方式,但我似乎无法得到它的工作,我结束了贯穿全在我的控制器使用的FormCollection循环党的形式,它只是乱了。

Is this possible? This seems like the most logical way to build grid/table structures in MVC(with each partial view being a table row) but I can't seem to get it to work and I end up using FormCollection in my controller to loop through the whole dang form, and it's just messy.

推荐答案

请参阅:

http://haacked.com/存档/ 2008/10/23 /模型绑定到一个-list.aspx

这是从连接到:

复杂的模型绑定到一个列表

<一个href=\"http://stackoverflow.com/questions/4163783/how-asp-net-mvc-how-can-i-bind-a-property-of-type-listt\">How ASP.NET MVC:我如何可以绑定一个List类型的属性

这篇关于如何绑定模式,以列表&LT;视图模型&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆