I'm working on ASP.Net MVC Core application and I have a view model with a list of integers:
public List<int?> SelectedIds { get; set; } = new List<int?>();
Now I want to access this property via javascript in order:
@model Project.ViewModels.Test.MyViewModel
$(function() {
var test = @Model.SelectedIds;
});
But in the Chrome console this is throwing an error:
var test = System.Collections.Generic.List`1[System.Nullable`1[System.Int32]];
What am I doing wrong?
CodePudding user response:
@model Project.ViewModels.Test.MyViewModel
$(function() {
var test = @Html.Raw(Json.Serialize(Model.SelectedIds));
});