Adalat  Khan

Adalat Khan

  • 652
  • 1.5k
  • 866.8k

Session in JavaScript

Jul 28 2019 4:23 AM
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:
 
<script type="text/javascript">
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;
}
}
 </script>
 
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
 
 

Answers (3)