In my web grids I have clickable rows that redirect to a different page while sending the id of the record along as Url Data
How does one store the id in a session variable??
$(document).ready(function () { $('.trclk').on('click', function () { location.href = '@Href("~/Members/NewFV/")' + $(this).parents('tr').find('td:first').text(); });
You can’t create session variables using JavaScript, so you need to add an extra command in the click handler that calls a server-side page which sets the session variable.
$(document).ready(function () { $('.trclk').on('click', function () { $.get('/yourSessionSettingPage/' + + $(this).parents('tr').find('td:first').text(); location.href = '@Href("~/Members/NewFV/")'; });
Your SessionSettingPage will contain something like this:
@{ var id = UrlData[0]; Session["SomeName"] = id; }
That’s it. You should be able to get the value of Session["SomeName"] in NewFV.cshtml.
Suppose the session variable already exists?
I create all the session variables I need when a new session starts. Storing data as I go along, and retrieving what I need when the time comes.
Is that a good approach?
wavemaster
Suppose the session variable already exists?
Then you will reset its value.
wavemaster
I create all the session variables I need when a new session starts. Storing data as I go along, and retrieving what I need when the time comes.
Is that a good approach?
If it works for you, then why not. Personally, I don’t use session variables in this way. There doesn’t seem to be much point. I just use UrlData or querystrings.