我有两个视图模型:
public class Parentviewmodel { public Id { get; set; } ..... public Childviewmodel Child{ get; set; } } public class Childviewmodel { public ChildId { get; set; } ..... }
控制器:
public ActionResult Index() { .... <some code> return View("NewIndex",Parentviewmodel); } [HttpPost] public ActionResult PartialAction(Childviewmodel childView) { return RedirectToAction("Index"); }
意见:
指数
@model Parentviewmodel .... @Html.Partial("_Partial",Model.Child)
和_Partial
@model Childviewmodel ... do some stuff with child model
传入字典的模型项目的类型为“Parentviewmodel”,但此字典需要一个类型为“Childviewmodel”的模型项目.