且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ASP.NET 5 MVC6中的布局文件中获取会话值

更新时间:2023-02-25 20:10:38

ContextHttpContext之间的命名有些混乱.您可以使用Context属性在视图中访问HttpContext:

The naming between Context and HttpContext is somewhat confusing. You can access the HttpContext in a view using the Context property:

@{ int x = Context.Session.GetInt32("test"); }

MVC存储库中还有一个与此相关的待解决问题: https://github.com/aspnet/Mvc/Issues/3332

There is also a pending issue at the MVC repo regarding this: https://github.com/aspnet/Mvc/issues/3332