I’m new to the whole MVC 3 style coding. I’m running into an issue, but first here’s how I have my website laid out.
_Layout.cshtml contains
@if (Request.IsAuthenticated)
{
<div class="span2">
@Html.Partial("_NavigationPartial")
</div>
<div class="span10">
@RenderBody()
</div>
}
else
{
@RenderBody()
}
@RenderBody will display my Profile.cshtml file that contains the following:
@{
ViewBag.Title = "My Profile";
}
<div class="row-fluid well">
<div class="page-header">
<h1>
Profile</h1>
</div>
@{
Html.RenderPartial("ChangePersonalInformationPartial");
Html.RenderPartial("ChangePasswordPartial");
}
</div>
As you see, I have two Partials (One to change the Personal Information, the other to Change the Password).
Each one of these Partials uses it’s own Model (ChangePersonalInformationModel and ChangePasswordModel).
My problem comes when I click submit on my ChangePasswordPartial, it reloads the _Layout.cshtml page but this time only loads up ChangePasswordPartial.cshtml. I need it to load up Profile.cshtml. But, if I go ahead and change under my AccountController.cs the return View(); to return View("Profile"); I get an error saying:
The model item passed into the dictionary is of type
‘PROJECT.Models.ChangePasswordModel’, but this dictionary requires a
model item of type ‘PROJECT.Models.ChangePersonalInformationModel’.
How can I fix this problem?
Thanks!
Basically you have to make a redirect to the profile action in the
ChangePasswordaction once you saved the password information.UPDATE:
First you should have a common model say
ProfileModelthat wraps up theChangePasswordModelandChangePersonalInformationModel.So here are the actions that displays the profile information for viewing and editing.
Your
EditProfile.cshtmlwill be like thisThis will be your
ChangePasswordaction