I have this certain viewmodel with viewmodels and collections. When I click save button that invokes postback, I can't get the viewmodels and collections inside the viewmodel. I need to declare 开发者_开发知识库viewmodels and collections in the parameter of the function in able to get it. Is there a way to get the viewmodel complete with it's viewmodels and collections?
I have this Customer viewModel
public class CustomerViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public PersonInfoViewModel PersonInfoViewModel { get; set; }
public ICollection<PurchasesViewModel> PurchasesViewModel { get; set; }
}
when I try to postback in my controller:
[HttpPost]
public ActionResult New(FormCollection collection, CustomerViewModel customerViewModel, PersonInfoViewModel personInfoViewModel, ICollection<PurchasesViewModel> purchasesViewModel)
{
customerViewModel.PersonInfoViewModel = personInfoViewModel;
...
}
I forgot to mention that the ViewModels and Collections are rendered using partial views. Thanks
You can't use RenderPertial for the rendering of a ViewModel in Viewmodel.
You have to use @Html.EditorFor(model => model.PurchasesViewModel)
Then make a folder named EditorTemplates
, either in the shared folder or in the folder you're surfing.
Next you have to create a view in that folder with the ViewModels name. So in your situation you have to make a view called PurchasesViewModel
精彩评论