Asp.net mvc identity current user path to razor view return 错误/传入字典的模型项

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

我正在使用 asp.net identity 2.0 并尝试将当前用户传递给 razor 视图。这是我的代码:

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

    return View(user);
}

但是在 razor 中我收到以下错误:

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

它说 razor 视图需要 ExternalLoginListViewModel 但在 razor 中我有一个模型 :

@model ExamsTraining.Models.User

我传递的是正确的模型...

根据您的例外情况,我认为您正在加载错误的视图。转到 Views/{Controller name folder}/Settings.cshtml 视图并确保那里有正确的模型。

如果您在视图或布局中使用 Html.Partial,问题可能会更严重。