我有一个使用视图模型的视图。在这个视图中,我在@using (Html.BeginForm())
块代码中使用了部分视图,如下所示
@foreach (var party in Model.Participants)
{
Html.RenderPartial("BlankEditorRow", party);
}
局部视图有一些文本框字段,用户可以在这些字段中输入数据。现在提交按钮没有放在局部视图中,而是放在主视图中。
在我看来,当我单击提交按钮时,我在视图模型中得到空值
[HttpPost]
public ActionResult ActionName(ViewModel model)
{
}
我不确定如何从部分视图中获取帖子数据。谁能帮我理解如何从部分视图发布数据?例子会有很大帮助
编辑:部分视图如下:
@model ASPNETMVCApplication.Models.Administration.Account.PartyModel
@使用 HtmlHelpers.BeginCollectionItem
<tr class="editorRow">
@using (Html.BeginCollectionItem("party"))
{
<td>@Html.TextBoxFor(m => m.FirstName, new { @style = "width: 100px;" })
</td>
<td>@Html.TextBoxFor(m => m.LastName, new { @style = "width: 100px;" })
</td>
<td>
@Html.DropDownListFor(model => model.PartyPersonalDetail.Gender, new SelectList(Model.Gender, "Id", "Name"), new { @style = "width: 100px;" })
</td>
<td>@Html.TextBoxFor(m => m.PartyPersonalDetail.MobilePhone, new { @style = "width: 100px;" })
</td>
<td>
@Html.DropDownListFor(model => model.PartyPersonalDetail.GothraId, new SelectList(Model.Gothras, "Id", "GothraName"), "--Don't Know--", new { @style = "width: 122px;" })
</td>
<td>
@Html.DropDownListFor(model => model.PartyPersonalDetail.NakshtraId, new SelectList(Model.Nakshtras, "Id", "NakshtraName"), "--Don't Know--", new { @style = "width: 122px;" })
</td>
<td>@Html.TextBoxFor(m => m.PartyPersonalDetail.EMail1, new { @style = "width: 135px;" })
</td>
<td>
<a href="#" class="deleteRow">Delete</a>
</td>
}
</tr>