I am doing an MVC 6 App
. I have a model like this
public class SearchModel
{
public string SSN { get; set; } = string.Empty;
public string EmployeeNumber { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string FirstName { get; set; } = string.Empty;
}
And I have it stored in a Session called SearchData
I need to see the data stored from chtml page. I have this
$(document).ready(function () {
var app = '@HttpContextAccessor?.HttpContext?.Session?.GetString("SearchData")';
});
But it returns all the data as a string.
How can I get specific field? like SSN
or EmployerName
? Do I have to parse it into Json Model?
Thanks
var searchData = JSON.parse(searchDataString.replace(/"/g, '"')); console.log(searchData.SSN);
var searchData = @Html.Raw(searchDataString); console.log(searchData.SSN)
no need to "parse" if it's already JSON. Depends on the format stored.app = '@Http....'
is being rendered - include that here (redact any personal information of course)