简体   繁体   中英

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...

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM