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.
-
stackoverflow.com/questions/2332082/…Massimiliano Peluso– Massimiliano Peluso2012-01-03 12:10:11 +00:00Commented Jan 3, 2012 at 12:10
Add a comment
|
1 Answer
Description
Just post to a controller and set the Session variable there.
Sample
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 });
}
}
More Information
1 Comment
unique
Is this good practice? set session values using ajax request?