我遇到了从视图模型映射到嵌套视图模型的属性的问题。我的结构(瘦身):
的ViewModels:
public class PolicyViewModel
{
public int PolicyId { get; set; }
public NoteViewModel NoteVM { get; set; }
}
public class NoteViewModel
{
public int PolicyId { get; set; }
}
政策制定者:
public ActionResult Adjustment(int policyId = 0, int historyId = 0)
{
GroupPolicyViewModel groupPolicyVM = new GroupPolicyViewModel();
// Automap all property values, then assign the policy Id to the nested controller?!
groupPolicyVM.NoteVM = new NoteViewModel { PolicyId = policyId };
return View(groupPolicyVM);
}
注意控制器
public int PolicyId { get; set; } // null
public JsonResult Get(int take, int skip, FilterExpression filter, NoteViewModel NoteVM)
{
// How do I get the PolicyId here?! NoteVM PolicyId is null
// This function is being called via jQuery from the Policy form and I obviously don't want to send the policyId via QueryString.
}
查看 当然,在我的观点中我有:
@Html.Partial("_Notes", Model.NoteVM)
@Html.HiddenFor(model => model.PolicyId)
@Html.HiddenFor(model => model.NoteVM.PolicyId) // also tried this with no success!
我想这应该是一个非常受欢迎的事情,但我无法弄清楚我做错了什么。有任何想法吗?我这样做是因为我需要多页的Note局部视图。