我试图绑定一个列表,该列表是较大的视图模型的一部分,而不依赖于自定义模型绑定器.当我使用编辑器模板来构建输入列表时,生成的名称的格式不正确,默认绑定器可以使用.
而不是物品[3].就像我期望它是物品.[3] .Id.如果我在没有编辑器模板的情况下构建列表,它将按预期工作.
我做了一些明显错误的事情,或者这只是Html.Hidden和Html.TextBox的怪癖?
public class ItemWrapper
{
[UIHint("ItemList")]
public IList<Item> Items { get; set; }
}
public class Item
{
public Guid Id { get; set; }
public string Name { get; set; }
public int Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
的Index.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
<% using(Html.BeginForm())
{%>
<%:Html.EditorFor(m => m.Items) %>
<%}%>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
ItemList.ascx
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IList<Mvc2Test.Models.Item>>" %>
<h4>Asset Class Allocation</h4>
<% if(Model.Count > 0) { %>
<table>
<tbody>
<% for(int i = 0; …Run Code Online (Sandbox Code Playgroud)