【问题标题】:ِِHow to Access the viewbag in the _viewstart.chtml in mvc 5?ِِ如何访问mvc 5中_viewstart.chtml中的viewbag?
【发布时间】:2020-09-27 16:03:55
【问题描述】:

我需要根据 _viewstart.chtml 中的用户更改布局。我已经在问题Why can't _ViewStart.cshtml access the ViewBag object? 中看到了答案,并且答案建议使用 ViewContext.ViewBag 但在 mvc 5 中我有错误

An object reference is required for the nonstatic field, method, or property 

那么我如何在 _viewstart.chtml 中使用 viewbag 或 ViewContext。

【问题讨论】:

    标签: asp.net-mvc razor asp.net-mvc-5


    【解决方案1】:

    代码将编译并且运行时没有错误,尽管 _viewstart 代码中有错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-11
      • 1970-01-01
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多