【发布时间】:2014-02-09 07:28:31
【问题描述】:
我有一个看起来像这样的复杂模型:
public class ModelOne()
{
//other stuff
public ModelTwo modelTwo {get;set;}
}
public class ModelTwo()
{
//other stuff
public List<ModelThree> modelThrees {get;set;}
}
public class ModelThree()
{
public int Id {get;set;}
public string Type {get;set;}
}
还有一个主视图
@model ModelOne
@using (Html.BeginForm("blah", "blah", FormMethod.Post, new { id = "blah" }))
{
//other form fields
<div id="partial">
@{Html.RenderPartial("partialView", ModelOne.modelTwo.modelThrees);
</div>
<input id="submitForm" type="submit" value="Submit" />
}
ModelThree 的局部视图
@model IList<ModelThree>
<table>
//header
@{for (int i = 0; i < Model.Count(); i++)
{
<tr>
@Html.HiddenFor(m => m[i].Id)
<td>
@(Html.Kendo().ComboBoxFor(m => m[i].Type)
.Filter("contains")
.Placeholder("Select type...")
.DataTextField("Text")
.DataValueField("Value")
.BindTo(new List<SelectListItem>() {
new SelectListItem() {
Text = "Some type", Value = "SomeType"
},
new SelectListItem() {
Text = "Other type", Value = "OtherType"
}
})
.HtmlAttributes(new { style = "width: 250px;" })
)
</td>
</tr>
}}
</table>
除了ModelThree 集合之外的所有内容都在表单提交中提交。
ModelThree 最初会按应有的方式绑定,如果我将对象添加到构造函数中的列表中,它们会按预期呈现,但在我提交表单时永远不会更新。是添加项目(我从这个示例中排除了添加逻辑)还是通过生成的下拉列表更新现有项目。
我需要做什么才能正确提交?生成的 HTML 通过索引看起来很正常,据我了解,它应该弄清楚如何从那里绑定它。
注意:我也尝试过通用下拉列表而不是剑道组合列表,结果相同。
【问题讨论】:
标签: c# ajax asp.net-mvc asp.net-mvc-4