Passing a javascript variable to session


I would like to know, how do I send a value that I have in javascript to a @session. in this case it would be something like this:

I have a variable:

var id = $(Person).val();

this ID I wanted to use in a session variable, but I tried to do it like this:

@Session["Person"] = id;

but when I run the page the error in javascript. how could I do it?


Why don't you send this id to the controller using json and put it in a viewbag, and use it in the view?

Scroll to Top