Description
Just send a message to the controller and set the session variable there.
Example
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 }); } }
Additional Information
dknaack
source share