Search code examples
c#asp.net-mvcasp.net-identity

Asp.net mvc identity current user path to razor view return error / The model item passed into the dictionary


I am using asp.net identity 2.0 and trying to pass current user to razor view. Here is my code :

public ActionResult Settings()
{
    string currentUserId = User.Identity.GetUserId();
    var user = _db.Users.Find(currentUserId);

    return View(user);
}

But in razor i'm getting the following error:

The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.User_D3D98E327FE171A79BDF8C79D31176E467C1EAF139BF185F0608911A37B99ECA', but this dictionary requires a model item of type 'ExamsTraining.Models.ExternalLoginListViewModel'.

It says that razor view needs ExternalLoginListViewModel but In razor i have a model :

@model ExamsTraining.Models.User

I'm passing a correct model...


Solution

  • From your exception I assume that you are loading the wrong view. Go to Views/{Controller name folder}/Settings.cshtml view and make sure that the correct model is there.

    The problem could be deeper if you are using Html.Partial in view or layout.