获取传递给部分视图的嵌套复杂对象的值。
public class MyViewModel{ public string SomeProperty { get; set; } public MyComplexModel ComplexModel { get; set; }}
public class MyComplexModel{ public int id { get; set; } public string Name { get; set; } public string Address { get; set; } ....}
public class MyController : Controller{ public ActionResult Index() { MyViewModel model = new MyViewModel(); model.ComplexModel = new MyComplexModel(); model.ComplexModel.id = 15; return View(model); } [HttpPost] public ActionResult Index(MyViewModel model) { // model here never has my nested model populated in the partial view return View(model); }}
@using(Html.BeginForm("Index", "MyController", FormMethod.Post)){ .... @Html.Partial("MyPartialView", Model.ComplexModel)}
@model my.path.to.namespace.MyComplexModel@Html.TextBoxFor(m => m.Name)...
ABOUTYOU