Access session variable in razor view .net core 2

前端 未结 3 1041
既然无缘
既然无缘 2021-02-04 01:45

I\'m trying to access session storage in a razor view for a .net core 2.0 project. Is there any equivalent for @Session[\"key\"] in a .net 2.0 view? I have not found a working e

3条回答
  •  悲&欢浪女
    2021-02-04 02:04

    As others have mentioned, I think the real solution here is not to do this at all. I thought about it, and while I have a good reason for using the session, since the razor tags are only useful for the initial page load anyway it makes more sense to just populate the view model in the controller with the stored session values.

    You can then pass the view model with the current session values to your view, and access your model instead. Then you don't have to inject anything into your view.

提交回复
热议问题