This is my Models code:
public class graph_user
{
public List year { get; set; }
}
This is my Views code side:
Assuming your model is actually @model graph_user
and not @model IEnumerable<graph_user>
(your current definition would not compile)
You can assign you models collection to a javascript variable using
var yearList = @Html.Raw(Json.Encode(Model.year))
Then iterate over it using
$.each(yearList, function(index, item) {
var year = item;
// do something with it
});
Side note: Recommend you follow normal naming conventions and name your property Years
- plural - (not year
) and your class GraphUser