Update
here is my solution that worked for me:
I create two sub views one for Model1 and one for Model2
and in the big view model I render them by :
@{Html.RenderPartial("view1", Model.model1);}
@{Html.RenderPartial("view2", Model.model2);}
and in the controller I have Action method like this
BigViewModel model= new BigViewModel();
return View(model);
and I have Action method for posting like this :
[HttpPost]
public ActionResult fun(Model1 model1,Model2 model2)
{
//Logic go here
}
=================================
I have a 2 models like this :
public class Model1 {
... more properties here ...
}
public class Model2 {
... more properties here ...
}
and then I created one big model : `
public class BigViewModel {
public Model1 model1 { get; set; }
public Model2 model2{ get; set; }
}
then created a strong typed view of type (BigViewModel)
so that user can edit the fields in that view and press submit button to back to server to process
public ActionResult test(BigViewModel model)
but the model is null.
I need a way to pass the BigViewModel to the controller.`
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…