1

我在将属性从我的视图模型映射到嵌套视图模型时遇到问题。我的结构(瘦身):

视图模型:

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 部分视图。

4

0 回答 0