我目前正在尝试从我的控制器传递动态数据到我的视图和布局。我目前使用ViewBag将数据从控制器传递到工作正常的视图。我无法从布局中访问ViewBag。有没有办法做到这一点?ASP.NET MVC5从布局访问ViewBag?
我使用ASP.NET W/MVC5(C#)。
编辑:更新W /代码:
//layout.cshtml
@ViewBag.username
息率这样的错误:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'ViewBag' does not exist in the current context
你能附加一些你试过的代码片段吗? –
你应该可以做到这一点。发布你的代码会有帮助。 – erdinger
你的'Views'目录中是否有Web.config?一些信息在这里:http://stackoverflow.com/questions/15550899/the-name-viewbag-does-not-exist-in-the-current-context和http://stackoverflow.com/questions/4960148/the- name-viewbag-does-exist-in-the-current-context – erdinger