【问题标题】:Controller property not exist on ViewContext object in ASP.NET Core MVCASP.NET Core MVC 中的 ViewContext 对象上不存在控制器属性
【发布时间】:2021-10-21 15:21:50
【问题描述】:

我有我当前的应用程序,它是用简单的 ASP.NET MVC 应用程序编写的,目前我正在将它迁移到 ASP.NET Core MVC。在我的旧应用程序中,我在 Razor 中有以下代码行

Culture CurrentRegisteredCulture = (this.ViewContext.Controller as EMPBaseController).CurrentRegisteredCulture;

现在在 ASP.NET Core 中,Controller 属性在 ViewContext 对象上不存在。如果有另一种方法可以让我获得与上述代码行相同的结果,您能否帮助我?

问候, 伊姆兰

【问题讨论】:

    标签: asp.net-mvc asp.net-core-mvc


    【解决方案1】:

    ASPNET Core中的ViewContext不是继承自ControllerContext,但是如果你想从ViewContext获取Culture,你可以尝试使用:

    Culture CurrentRegisteredCulture = this.ViewContext.HttpContext.Features.Get<IRequestCultureFeature>().RequestCulture.Culture;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多