I have a main view with a model AViewModel:
public class AViewModel
{
public int P1 { get; set; }
public BViewModel P2 { get; set; }
}
I have a partial view with BViewModel:
public class BViewModel
{
public string P1 { get; set; }
public string P2 { get; set; }
}
From the main view I render the partial view as the following.
await Html.RenderPartialAsync("~/Views/_B.cshtml", Model.P2);
On the main view, on submit ([HttpPost] Index controller method), I'm expecting the AViewModel.P2 to be populated with the BViewModel coming from the partial view, but it's not. What am I doing wrong? Is there a way to populate the original property (namely AViewModel.P2) with information collected from the partial view?
In other words, the problem is that on the controller method, model.P2.P1 and model.P2.P2 are null