[英]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. 我正在使用asp.net Identity 2.0,并尝试将当前用户传递到razor视图。 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'.
传递到字典中的模型项的类型为“ System.Data.Entity.DynamicProxies.User_D3D98E327FE171A79BDF8C79D31176E467C1EAF139BF185F0608911A37B99ECA”,但此字典需要类型为“ ExamsTraining.Models.ExternalLoginListViewModel”的模型项。
It says that razor view needs ExternalLoginListViewModel but In razor i have a model : 它说剃刀视图需要ExternalLoginListViewModel但在剃刀中我有一个模型:
@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. 转到
Views/{Controller name folder}/Settings.cshtml
视图,并确保存在正确的模型。
The problem could be deeper if you are using Html.Partial
in view or layout. 如果在视图或布局中使用
Html.Partial
,则问题可能更Html.Partial
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.