首页 > 解决方案 > ِِ如何访问mvc 5中_viewstart.chtml中的viewbag?

问题描述

我需要根据 _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-mvcrazorasp.net-mvc-5

解决方案


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

在此处输入图像描述


推荐阅读