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\
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 Controller
public class SetSessionController : Controller
{
public ActionResult SetVariable(string key, string value)
{
Session[key] = value;
return this.Json(new { success = true });
}
}