请问模型绑定在ASP.NET MVC Beta版支持列表&LT; T&GT ;? [英] Does the Model Binder in ASP.NET MVC Beta Support List<T>?
本文介绍了请问模型绑定在ASP.NET MVC Beta版支持列表&LT; T&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下面的例子类。我想显示一个表单上的用户和两个地址(从列表)。在是否MVC的测试模型绑定支持这个或将我写我自己的定制绑定?
公共类客户
{
公共字符串名字{获得;组; }
公共字符串名字{获得;组; }
公开名单&LT;地址&gt;地址{搞定;组; } 公众客户()
{
地址=新的List&LT;地址&gt;();
}}公共类地址
{
公众诠释线路1 {搞定;组; }
公众诠释2号线{搞定;组; }
公众诠释市{搞定;组; }
公众诠释国家{搞定;组; }
公众诠释邮编{搞定;组; }
}
你将如何code中的字段?喜欢这个?
&LT;! - 一些HTML格式 - &GT;
&所述;%= Html.TextBox(customer.address.line1,ViewData.Customer.Address [0] .Line1)%GT;
&LT;! - 一些HTML格式 - &GT;
&所述;%= Html.TextBox(customer.address.line1,ViewData.Customer.Address [1] .Line1)%GT;
&LT;! - HTML表单格式的结束 - &GT;
解决方案
我从来没有尝试过,但看到的这个帖子,它是关于模型绑定到一个列表,也许它可以帮助你。
Take the example classes below. I want to display the customer and two addresses (from a LIST) on a form. Does the model binder in MVC beta support this or will I have to write my own custom binder?
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public List<Address> Addresses { get; set; }
public Customer()
{
Addresses = new List<Address>();
}
}
public class Address
{
public int Line1 { get; set; }
public int Line2 { get; set; }
public int City { get; set; }
public int State { get; set; }
public int Zip { get; set; }
}
How would you code the fields? Like this?
<!-- some HTML formatting -->
<%= Html.TextBox("customer.address.line1", ViewData.Customer.Address[0].Line1)%>
<!-- some more HTML formatting -->
<%= Html.TextBox("customer.address.line1", ViewData.Customer.Address[1].Line1)%>
<!-- end of HTML form formatting -->
解决方案
I've never tried it, but see this post, it's about model binding to a list, maybe it can help you.
这篇关于请问模型绑定在ASP.NET MVC Beta版支持列表&LT; T&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文