The view automatically encodes string content to protect you from nasty JavaScript injection. You must opt-in if you trust the string content.
var data = @Html.Raw(Model.JsonNotifications);
console.log(data);
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I serialized my data to JSON from the controller:
// Serialization
string jsonActivities = JsonSerializer.Serialize(ViewUserNotifications);
ModelData.JsonNotifications = jsonActivities;
View:
@默 .JsonNotifications
[{"Id":7,"UserSender":10,"UserReciever":4,"UserSenderName":"Maya","UserSenderSurname":"Robertson","UserSenderProfileImage":"88cf1027-eafd-493f-8b9c-add3f6812eb0_64.jpg","Message":"Maya is following you","Seen":true,"Created":"2021-09-04T21:07:50.3294555","Status":3}]
I wonder how can I use this Json data with javascript?I tried like this:
JS:
var data = JSON.parse(@默 .JsonNotifications);
console.log(data);
However, in the console I got an error:
Uncaught SyntaxError: expected property name, got '&'
Any help is appreciated!
The view automatically encodes string content to protect you from nasty JavaScript injection. You must opt-in if you trust the string content.
var data = @Html.Raw(Model.JsonNotifications);
console.log(data);