如何使用jQuery在ASP.NET MVC 3中设置Session变量?
所以这就是问题:如何使用jQuery在ASP.NET MVC 3中设置Session变量?
我正在尝试使用$.ajax
或$.post
但问题是我真的不知道该怎么做。
描述
只需发布到控制器并在那里设置Session变量。
样品
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 }); } }
更多信息
- 在MVC 3应用程序中使用JQuery通过Ajax保存和检索会话数据