Set mvc session values using jQuery

QuestionsCategory: Asp.netSet mvc session values using jQuery
Alen asked 11 months ago

How to Set MVC session values using jQuery?

I want to set the Dropdown selected value in Session. I have done in Code behind. But for some condition, i have to Do in Client Side Itself.

1 Answers
Shehryar Khan Staff answered 11 months ago

you can directly Get the value of Session in JavaScript but setting Session value from JavaScript is little tricky.
You can do something like this..

$(function () {
           { 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 });