传参到其它页面

开发工具与关键技术:VS   ,   ASP.NET.MVC;

作者:吴维杰

撰写时间:2019.07.10

--------------------------------------------------------------------------------------------------------------------------------------------

传参到其它页面是一种简易而实用的传参方法,

下面演示一下把登录页面的用户名称和用户类型,传参到其它页面显示的效果.

首先获取登录页面的参数.

string strUserId = Session["UserID"].ToString();

                string UserTypeClass = Session["UserTypeClass"].ToString();

                string strUserTypeId= Session["UserTypeID"].ToString();

                string strUserName = "";//用户名称

                string strUserTypeClass = "";//用户类型

                int userId = Convert.ToInt32(strUserId);

                int userTypeId = Convert.ToInt32(strUserTypeId);

                strUserName = (from pwUser in myModels.PW_User

                               where pwUser.UserID == userId

                               select pwUser.UserName).Single();

                ViewBag.userName = strUserName;

         strUserTypeClass = (from tbUserType in myModels.SYS_UserType

                             where tbUserType.UserTypeID == userTypeId

                             select tbUserType.UserTypeName).Single();

                ViewBag.userTypeClass = strUserTypeClass;

然后在页面上获取传过来的参数.如下.

<p class="float-left col-9 p-1 mt-2" style="color:black"><span>用户名:</span>@ViewBag.userName</p>

 

<p class="float-left col-9 p-1" style="color:black"><span>用户类型:</span>@ViewBag.userTypeClass</p>

效果如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值