So I've tried to follow multiple threads on here to do what I am to, and so far it all seems to have something to do with a singleton which I think is a bit over-the-top solution for my issue.
I'm trying to do the following: I have my login async task which is executed when the user logins in a partial view, then it takes a LoginViewModel as a parameter, when succesfully logged in this happens:
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
Afterwards when my users click into the Member section as follows:
@Html.ActionLink("Medlemsområde", "LoggedIn", "Home", null, new { @class = "login-field btn btn-primary" })
My home controller looks like this
public ActionResult LoggedIn()
{
if (User.Identity.IsAuthenticated)
return View("Dashboard");
else
return View("Login");
}
My dashboard looks like this
@{
Html.RenderAction("Index", "Manage");
}
And then I have my Manage controller
public async Task<ActionResult> Index(ManageMessageId? message)
{
ViewBag.StatusMessage =
message == ManageMessageId.ChangePasswordSuccess ? "Dit password er blevet ændret."
: message == ManageMessageId.SetPasswordSuccess ? "Dit password er gemt."
: message == ManageMessageId.SetTwoFactorSuccess ? "Din to-faktor godkendelse er gemt."
: message == ManageMessageId.Error ? "Der skete en fejl."
: message == ManageMessageId.AddPhoneSuccess ? "Dit telefon nummer blev tilføjet."
: message == ManageMessageId.RemovePhoneSuccess ? "Dit telefon nummer blev fjernet."
: "";
var userId = User.Identity.GetUserId();
var model = new IndexViewModel
{
HasPassword = HasPassword(),
PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
Logins = await UserManager.GetLoginsAsync(userId),
BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
};
return View(model);
}
Whenever I have
Html.RenderAction("Index", "Manage");
I get the following error:
The model item passed into the dictionary is of type 'ClientSideProgramming.Models.IndexViewModel', but this dictionary requires a model item of type 'ClientSideProgramming.Models.LoginViewModel'.
How can I fix this without ending up with either passing models all around, or having a singleton?