In my viewModel i want to get the current session value. For that i have written like this :
self.currentUserId = ko.observable(HttpContext.Current.Session["UserID"]);
But its showing me error that
ReferenceError: HttpContext is not defined.
How to define HttpContext? OR Is there any way to get current session value?
Change your statement
To
If your application using webform and viewmodel is inline with aspx page
if MVC with razor view engine with inline viewmodel of view
and if your viewmodel is in external js file, then first store it in a js variable and use in that js
like, you can’t use
HttpContext.Current.Session["UserID"]in external js file.in
<your_view_model_js>file use