I know that view model can be used for rendering a view, but if a page needs different models, how can I pass them to the view? And how do I use them?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you need to pass multiple models then create an all-encompassing model that has the smaller models hanging off as properties.
For instance, let’s say you are going to display a page for managing groups of users for your app. You would probably need to pass an
IEnumerable<UserDisplayModel>and also anIEnumerable<GroupDisplayModel>to the view. Create a new display model like this:Pass instances of this model to your view instead.