Within my ViewModel, I have an Items collection:
public class ItemViewModel{
public List<Item> Items {get;set;}
}
In the Index.cshtml
file:
@if(Model.Items != null){
<li><a id="item-id-link" href="#" data-items="@Model.Items"> ...
}
I am attempting to retrieve data using TypeScript:
function getData(context: Jquery){
....
context.find("item-id-link").click(e => {
const items = #(e.target).data('data-items');
});
}
However, when accessing the items, I get a list of item datatype instead of actual items:
"System.Collections.Generic.List`1[ItemViewModel]"
I have tried using a for of
loop to inspect each element in the list:
for (let item of items) {
console.log(item);
}
Unfortunately, this returns each word of
"System.Collections.Generic.List'1[ItemViewModel]"
Adding .ToList()
in the Razor Page did not resolve the issue.
Any suggestions on how to handle this situation?