This is the code I wrote in my .cshtml file:
@ { var myList = (List<MyViewModel>)ViewBag.MyCollection; }
<input id="myListHidden" type="hidden" data-my-list="@myList" />
Next, here is the TypeScript code that retrieves the value from above:
let _myList = $('#myListHidden').data('my-list');
The return value is:
"System.Collections.Generic.List`1[MyProject.Data.ViewModels.MyViewModel]"
I am attempting to iterate through this collection by using the following code:
for (let entry of _myList ) {
console.log(entry);
}
However, it only outputs System.Collections.Generic.List
as a string. I need to access and iterate through all the values inside the collection.
Edit:
The properties of MyViewModel are as follows:
public long Id { get; set; }
public string Name { get; set; }
public bool Active { get; set; }