简体   繁体   English

Asp.net MVC身份当前用户到剃刀视图的路径返回错误/将模型项传递到字典中

[英]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.

相关问题 ASP.NET MVC:传递到词典中的模型项的类型为“ ClassA”,但是此词典需要类型为“ ClassA”的模型项 - ASP.NET MVC: The model item passed into the dictionary is of type 'ClassA', but this dictionary requires a model item of type 'ClassA' ASP.NET 核心 MVC - Model 属性传递给视图,显示 ZE405C1DF83BD248A07FC9A9122 中的 null - ASP.NET Core MVC - Model properties passed to view showing null in Razor 传递到字典中的模型项在ASP.net MVC中的类型为“ System.Collections.Generic.List…” - The model item passed into the dictionary is of type 'System.Collections.Generic.List… in ASP.net MVC ASP.Net MVC“传入字典的模型项是'System.Collections.Generic.List'类型” - ASP.Net MVC “The model item passed into the dictionary is of type 'System.Collections.Generic.List” 鉴于一台服务器上的ASP.Net MVC站点而不是另一台服务器上的HttpContext.Current.User.Identity为空/空 - HttpContext.Current.User.Identity is null/empty in view of ASP.Net MVC site on one server but not the other ASP.NET 核心 MVC 身份 - 如何查看当前登录的用户? - ASP.NET Core MVC Identity - how to get current logged in user in view? asp.net mvc 3剃刀更改视图中的模型值 - asp.net mvc 3 razor change model value in view Css视图模型与asp.net mvc中的剃刀 - Css view Model with Razor in asp.net mvc asp.net mvc4 razor将视图模型传递给帮助器 - asp.net mvc4 razor pass view model to helper 使用Web API的ASP.NEt MVC返回Razor视图 - ASP.NEt MVC using Web API to return a Razor view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM