asp.net mvc中的会话问题 [英] session problem in asp.net mvc

查看:55
本文介绍了asp.net mvc中的会话问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在cshtml视图中基于userrole创建条件,这应该在sitemenu类中。

I want to make condition in cshtml view based on userrole that should be in sitemenu class like this.

this.UserRole = userlist[0].UserRole.Tostring();

HttpContext.Session["UserRole"]=this.UserRole;





查看



In view

<script>

var userRole=@HttpContext.Session["UserRole"].Tostring();

alert(userRole);

</script>



我的问题是会话值未显示在警告框中。



那么如何使用session在我的页面中处理这个问题。因为如果我想使用viewBag或ect,那不是控制器。


My problem is the session value is not displaying in alert box.

So how to handle this in my page using session. Because that is not controller if I want to use viewBag or ect.

推荐答案

好的,我知道了



i已经删除了脚本块中的@HttpContext,

并维护@Session只是现在它正常工作..
Ok i got it

i have removed "@HttpContext" in script block,
and maintained @Session only now it is working fine..


这篇关于asp.net mvc中的会话问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆