如何将 Session 与 Nancy Razor ViewEngine 结合使用
我正在将 RazorViewEngine 用于 NancyFx,并且我希望有一个类似 ViewBag 的对象,可以在其中存储动态属性。尽管并不理想,但我认为会话状态足以满足我的目的。我在 Bootstrapper 的 ApplicationStartup 方法中启用了 CookieBasedSession,并添加了 BeforeRequest Pipeline 方法来设置 Session 变量。但是,我不知道如何检索视图中的值。如果不将 Session 变量添加到模型中,这可能吗?会话状态是否只能在模块中访问?
(从 nancy-fx 论坛交叉发布)
I'm using the RazorViewEngine for NancyFx and I would like to have a ViewBag like object where I can store dynamic properties. Although not ideal, I decided that Session state would suffice for my purposes. I've enabled CookieBasedSession in my Bootstrapper's ApplicationStartup method, and I added a BeforeRequest Pipeline method to set the Session variable. However, I don't know how to retrieve the value in my View. Is this possible, without adding the Session variable to a model? Is the Session state only meant to be accessed in modules?
(cross posted from the nancy-fx forum)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
截至目前,您将需要通过视图模型传递值。无法从视图内部直接访问会话状态
As of right now you will need to pass in the values though your view model. There is no direct access to the session state from inside a view