In my AP.NET MVC application I'm setting a session variable from JQuery like below.
HTML
<a href="/Time" onclick="SetTraineeModel({{userId}})"><img src='../Content/themes/base/img/icon-arrow-table-view.png'></a>
abc.js
function SetTraineeModel(userId) {
$.ajax({
url: $('#rootUrl').val() + "Notifications/SetTraineeModel",
async: false,
data: {
Id: userId
},
success: function (data) {
}
})
}
The session variable is successfully set in the method SetTraineeModel of Notifications Controller.
However the variable is null when the href method is hit after the click handler. i.e in the method Index of Time controller.
I'm not sure why the session variable is lost in this scenario?
Note: {{userId}} above is from handlebars.js template.
Here is my Controller method:
public void SetTraineeModel(string Id)
{
var model = new TraineeModel();
model.CurrentTraineeId = Id;
HttpContext.Current.Session["CurrentTrainee"] = model;
}