ِِ如何在mvc 5中访问_viewstart.chtml中的viewbag?

问题描述 投票:0回答:1

我需要根据_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个回答
0
投票

尽管_viewstart代码中有错误,但是该代码可以编译,并且在运行时中没有错误。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.