Hi!
How i can update Multiple Models ?
I use View Model from this article(http://www.c-sharpcorner.com/UploadFile/ff2f08/multiple-models-in-single-view-in-mvc/)
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dharmesh SinghRank #1,207 · 1.5K reputationPosted Apr 22, 2016, 6:50 PM EDT
You can create a view model that combines all the fields you need from the other models, and strongly type your view to that. Once the user submits the info back to the controller, you'll process each property appropriately.
public class RegisterViewModel()
{
//Userinfo
public string UserName {get; set;}
...
//Extended user info
public string FirstName {get; set;}
public string LastName{get; set;}
...
//Benefits
public string BenefitName {get; set;}
...
}
and then
[HttpPost]
public ActionResult Register (RegisterViewModel viewModel)
{
//grab the user info from the view model and process it
viewModel.UserName...
//grab the extended info and process it
viewModel.FirstName...
//grab the benefit info and process it
viewModel.BenefitName...
}