0

I have a view called AccountManager on this view I have a section to update your profile information and update your password.

Both functions require a different model. ManageUserViewModel and ChangePasswordViewModel.

On the AccountManager view, both sections are rendered via @Html.Partial.

When I try to display the page, I receive the following error: "The model item passed into the dictionary is of type 'WebUI.Models.ManageUserViewModel', but this dictionary requires a model item of type 'WebUI.Models.ChangePasswordViewModel'."

How can I render both views without receiving this error?

Justin Adkins
  • 1,214
  • 2
  • 23
  • 41
  • http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc – Matt Bodily Dec 12 '13 at 20:22
  • I understand what a ViewModel is in MVC. That wasn't my question. My question is, how do you display a view with two different Models. – Justin Adkins Dec 12 '13 at 20:24
  • 1
    you put both models into a view model and on your view you use the model that pertains. something like @Html.RenderPartial("_PartialName", Model.ChangePaswordViewModel) – Matt Bodily Dec 12 '13 at 20:33

1 Answers1

2

ViewModel:

public class AccountManagerViewModel
{ 
    public ManageUserViewModel manageUserViewModel { get; set; }
    public ChangePasswordViewModel changePasswordViewModel { get; set; }
}

The View:

@model AccountManagerViewModel
/*HTML CODE*/
@Html.RenderPartial("_PartialChangePassword", Model.changePasswordViewModel)
@Html.RenderPartial("_PartialManageUser", Model.manageUserViewModel)

So you just play with the viewModels. Remember that they can have anything you need in the view. Let me know.

Guillermo Oramas R.
  • 1,303
  • 2
  • 14
  • 31