我怎样才能将所选项目设置为会话MVC(剃刀)? [英] How could I set selected item to session MVC(razor) ?

查看:66
本文介绍了我怎样才能将所选项目设置为会话MVC(剃刀)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将选定的项目从下拉列表设置为MVC5中的Session,以便它可以在应用程序的任何地方用于当前用户,请告诉我有没有其他解决方法?



我尝试过:



@ Html.DropDownList(CompanyList,ViewBag.CompanyList作为SelectList,

选择公司,新{id =CompanyId})







< input type =buttonvalue =Goid =btnSelect

/>

@section scripts

{

< script>

$(#btnSelect)。点击(

function()

{

var value = document.getElementById(CompanyId)。value;

@ Context.Session [CompanyId] ='+ value + ';

alert(会话+ @ Context.Session [CompanyId]。ToString());

}

) ;

< / script>

}





但这会将表达式作为会话点返回给NUll

I want to set selected item from dropdown to Session in MVC5 ,so that it can be used anywhere in the application for the current user, Kindly let me know is there any other workaround?

What I have tried:

@Html.DropDownList("CompanyList", ViewBag.CompanyList as SelectList,
"Select a Company", new { id = "CompanyId" })



<input type="button" value="Go" id="btnSelect"
/>
@section scripts
{
<script>
$("#btnSelect").click(
function ()
{
var value = document.getElementById("CompanyId").value;
@Context.Session["CompanyId"]="'"+value+"'";
alert( "Session "+ @Context.Session["CompanyId"].ToString());
}
);
</script>
}


but this returns expression being session points to NUll

推荐答案

(#btnSelect)。点击(

函数()

{

var value = document.getElementById(CompanyId )。值;

@ Context.Session [CompanyId] ='+ value +';

alert(Session+ @ Context.Session [CompanyId] .ToString());

}

);

< / script>

}





但这会将表达式作为会话点返回给NUll
("#btnSelect").click(
function ()
{
var value = document.getElementById("CompanyId").value;
@Context.Session["CompanyId"]="'"+value+"'";
alert( "Session "+ @Context.Session["CompanyId"].ToString());
}
);
</script>
}


but this returns expression being session points to NUll


这篇关于我怎样才能将所选项目设置为会话MVC(剃刀)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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