简体   繁体   中英

Access ViewModel integer list with javascript

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?

@model Project.ViewModels.Test.MyViewModel

  $(function() {
                 var test = @Html.Raw(Json.Serialize(Model.SelectedIds));
   });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM