我有两个模型:
class ModelIn{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
}
class ModelOut{
public ModelOut(){ People = new List<ModelIn>();}
public List<ModelIn> People { get; private set;}
public string Country { get; set; }
}
我有控制器编辑 ModelOut:
public ActionResult People()
{
...
return View(SomeModelOutInstanceWith3People);
}
[HttpPost]
public ActionResult(ModelOut items)
{
...
}
鉴于我有这样的事情:
<% using (Html.BeginForm()) { %>
<%: Html.EditorFor(m => Model.Country) %>
<% for(int i = 0; i < Model.People.Count; ++i){ %>
<%: Html.EditorFor(m => Model.People[i].FirstName) %>
<%: Html.EditorFor(m => Model.People[i].LastName) %>
<%: Html.EditorFor(m => Model.People[i].Address) %>
<% } %>
<input type="submit" />
<% } %>
一切正常,但在后期操作中,我有空的 ModelOut 项目。我可以在日志中看到数据已正确发送。
我已经尝试了一切,没有任何效果。