Last post Jan 17, 2018 03:36 PM by mgebhard
Jan 17, 2018 03:29 PM|Mestric|LINK
I have an extension method for sessions from MS docs
public static class SessionExtensions
public static void Set<T>(this ISession session, string key, T value)
public static T Get<T>(this ISession session,string key)
var value = session.GetString(key);
return value == null ? default(T) :
I'm using that to store values in a class.
I read this but it's not for Core 2.0
I use this to get data from controller:
var Partner = HttpContext.Session.Get<PartnerData>("Partner");
Jan 17, 2018 03:36 PM|mgebhard|LINK
1) Write the Session value to the View using Razor syntax. You can write the value in hidden field(s) or really any HTML element you like. If Session holds a complex type then use a JSON serializer to craft a JSON object in a <script> tag.
2) Use AJAX to retrieve the Session value by calling a controller action.
Keep in mind that this question has nothing to do with ASP Core or any server side website framework. This question is related to how web applications work at a fundamental level.