如何设置会话在ASP.NET MVC 3使用jQuery变量? [英] How set Session variables in ASP.NET MVC 3 with jQuery?

查看:132
本文介绍了如何设置会话在ASP.NET MVC 3使用jQuery变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,这是一个问题:?在会议ASP.NET MVC 3使用jQuery如何设置变量结果
我试图用 $。阿贾克斯 $。POST 但问题是,我真的不知道该怎么做。

So this is the question: how set Session variables in ASP.NET MVC 3 with jQuery?
I'm trying to use $.ajax or $.post but the problem is that I don't really know what to do.

推荐答案

刚刚张贴到控制器,并设置会话变量在那里。

Description

Just post to a controller and set the Session variable there.

的jQuery

$(function () {
    $.post('/SetSession/SetVariable', 
           { key : "TestKey", value : 'Test' }, function (data) 
    {
        alert("Success " + data.success);
    });
});

的mvc控制器

public class SetSessionController : Controller
{
    public ActionResult SetVariable(string key, string value)
    {
        Session[key] = value;

        return this.Json(new { success = true });
    }
}

更多信息


  • Save并在MVC 3应用程序
  • 使用JQuery通过Ajax检索会话数据

    More Information

    • Save and retrieve Session data via Ajax using JQuery in an MVC 3 application
    • 这篇关于如何设置会话在ASP.NET MVC 3使用jQuery变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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