复杂的模型绑定到一个列表 [英] Complex model binding to a list

查看:104
本文介绍了复杂的模型绑定到一个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试了NameValueDeserializer从MVCContrib,这将需要一个IList中作为参数传递给控制器​​和绑定的形式和它的元素,但我只是想知道如果MVC的测试有这样做的任何方式?

I have been trying out the NameValueDeserializer from MVCContrib, which will take a IList as a parameter to a controller and bind a form and its elements to it, but I was just wondering if MVC Beta had any way of doing this??

我知道你可以绑定一个强类型的对象,但我想对这些对象的List绑定一些批量编辑的情况。

I know you can bind a strongly typed Object but I want to bind a List of these Objects for some bulk editing situations.

如:

public void Save(IList<Item> items)
{
    foreach (Item i in items)
    {
        //Save item
    }
}

这是有可能在MVC的测试?
先谢谢了。

Is this possible in MVC Beta?? Thanks in Advance.

推荐答案

是的,我写了一个详细的博客文章在这里。这真的很容易为简单类型。对于复杂的类型,你需要做的是这样的:

Yes it is, I wrote a detailed blog post about it here. It's really easy for simple types. For complex types, you'd need to do something like:

<input type="hidden" name="products.Index" value="0" />
<input type="text" name="products[0].Name" value="Beer" />
<input type="text" name="products[0].Price" value="7.32" />

<input type="hidden" name="products.Index" value="1" />
<input type="text" name="products[1].Name" value="Chips" />
<input type="text" name="products[1].Price" value="2.23" />

<input type="hidden" name="products.Index" value="2" />
<input type="text" name="products[2].Name" value="Salsa" />
<input type="text" name="products[2].Price" value="1.23" />

这篇关于复杂的模型绑定到一个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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