我有一个用于呈现对象列表的html表。我正在调用一个控制器动作,它接收Model作为参数,但模型的列表都是空的。我已经尝试了我能找到的所有建议,但无法让它发挥作用。我是MVC 4的新手,我不确定问题出在模型绑定中,还是我调用Controller的方式。
Obs:我目前正在使用其他项目/命名空间中的模型,这可能会让绑定混乱吗?
模特细节: ob有一个包含行列表的行列表。
查看代码:
@model SF.obDTO
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>User</legend>
<div class="editor-label">
@Html.LabelFor(model => model.DateCreation)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DateCreation)
@Html.ValidationMessageFor(model => model.DateCreation)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DateCreation)
@Html.ValidationMessageFor(model => model.DateCreation)
</div>
@Html.HiddenFor(model => model.ListUserNotes)
<table>
<tr>
<th>Conteúdo
</th>
<th>Completo
</th>
</tr>
@InsertSubLines(Model.ListLines, 0)
</table>
<p>
@Ajax.ActionLink("Save", "Save", Model, new AjaxOptions { HttpMethod = "POST" })
</p>
</fieldset>
}
@helper InsertSubLines(List<SF.LineDTO> pLines)
{
if (pLines != null)
{
for (int i = 0; i < pLines.Count(); i++)
{
<tr>
<td>
@Html.TextBoxFor(modelItem => pLines[i].Content)
</td>
<td>
@Html.DisplayFor(modelItem => pLines[i].Completed)
</td>
@InsertSubLines(pLines[i].ListLines)
@Html.HiddenFor(modelItem => pLines[i].ListLines)
</tr>
}
}
}
控制器代码
[HttpPost]
public ActionResult Save(SF.obDTO pOB)
{
SF.Update(pOB);//Here the sublists are empty (count = 0)
return null;
}