I am using MVC Core. In my application i want to set the Session value in JavaScript but it gives me error "Cannot implicitly convert type void to type object". When i get the Session Value then it working properly but when i set value of Session in JavaScript then it gives me the above error. Following is my JavaScript Code:
var seconds = @HttpContextAccessor.HttpContext.Session.GetString("SessionSeconds");
var minutes = @HttpContextAccessor.HttpContext.Session.GetString("SessionMinutes");
var hours = @HttpContextAccessor.HttpContext.Session.GetString("SessionHours");
function CountDownSessionTime() {
if (seconds > 0) {
seconds = seconds - 1;
}
else
if (seconds == 0) {
@HttpContextAccessor.HttpContext.Session.SetString("SessionSeconds", "60");
minutes = minutes - 1;
}
}
The first three lines are working in which i am getting values of Seconds, Minutes, and Hours which i have set in my Controller but in JavaScript i also want to set the value of Seconds in Session but it gives me error. The following line of code give me Error:
@HttpContextAccessor.HttpContext.Session.SetString("SessionSeconds", "60");
The above line give me error "Cannot implicitly convert type void to type object". Please give me an idea how i can set value of Session in JavaScript in MVC Core Application. Thanks
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Bidyasagar MishraPosted Jul 28, 2019, 6:56 AM
Adalat KhanPosted Jul 28, 2019, 6:46 AM
Bidyasagar MishraPosted Jul 28, 2019, 6:04 AM