How to get asp.net Session value in jquery method?

前端 未结 6 1474
迷失自我
迷失自我 2020-12-13 16:11

I want to access a Session value in jquery method in the ASP.NET MVC view page. See the below code,

$(\'input[type=text],select,input[type=checkbox],input[ty         


        
6条回答
  •  眼角桃花
    2020-12-13 16:52

    Not sure if this is the best route but within your aspx page you could create a method that returns the value of your session variable, e.g.

    Server side:

    using System.Web.Services;
     [WebMethod(EnableSession = true)]
    public static string GetSession()
    {
       return Session["CoBrowse"].ToString();
    }
    

    then call this method client side using jQuery:

    $.ajax({
        type: "POST",
        url: "./Default.aspx/GetSession",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(result){
            ('input[type=text],select,input[type=checkbox],input[type=radio]').attr('disabled', result.d);
        }
    });
    

提交回复
热议问题