在我的示例MVC应用程序,我有一个模型更新局部视图模型值提交
class SampleModel
{
public int Id { get; set; }
public string Name { get; set; }
public List<Certification> Certifications { get; set; }
}
class Certification
{
public int Id { get; set; }
public string CertificationName { get; set; }
public int DurationInMonths { get; set; }
}
我的视图(我需要在一个局部视图中显示的认证信息)
@model SampleApplication.Model.SampleModel
<!-- other code... -->
@using (Html.BeginForm("SaveValues","Sample", FormMethod.Post, new { id= "saveForm" }))
{
@Html.HiddenFor(m => m.Id, new { id = "hdnID" })
@Html.TextBoxFor(m => m.Name, new { id = "txtName" })
@{Html.RenderPartial("_CertDetails.cshtml", Model.Certifications);}
<input type="submit" id="btnSubmit" name="btnSubmit" value="Update" />
}
局部视图
@model List<SampleApplication.Model.Certification>
<!-- other code... -->
@if (@Model != null)
{
for (int i = 0; i < @Model.Count; i++)
{
@Html.HiddenFor(m => m[i].Id , new { id = "CId" + i.ToString() })
@Html.TextBoxFor(m => m[i].CertificationName,new{ id ="CName" + i.ToString() })
@Html.TextBoxFor(m => m[i].DurationInMonths,new{ id ="CDur" + i.ToString() })
}
}
控制器
[HttpPost]
public ActionResult SaveValues(SampleModel sm)
{
//Here i am not getting the updated Certification details (in sm)
}
如何到局部视图的更新值在表单提交后,我的控制器?当我不使用partialview时,我能够获得更新的认证值。 这是正确的方式,还是应该遵循其他一些方法?
嗨克里斯感谢您的答复......我添加了一些认证值的模型。这些值正在呈现正确。当我更新这些值并发布表单时,我得到更新的“示例”,但“认证”中的内容为空。如果我使用相同的方法,是否有可能获得这些值? – san
是的,再次,如果它为空,则什么都没有公布(请确保你没有做一些愚蠢像使用多个'