Reputation: 157
Model.kanal is an array. I need a loop like this:
var boyut = @Model.kanal.Length;
var knll = [];
for (var i = 0; i < boyut; i++) {
knll.push("@Model.kanal[i]"); //this i variable is not defined. Because it is a javascript variable. This is my problem.
}
Thank you.
Upvotes: 0
Views: 328
Reputation: 209
try this
var boyut = @Model.kanal.Length; // Get Model Array Length
var knll = "@Html.Raw(Json.Serialize(Model.kanal))"; // Convert Array into Json and Set a Plan Text
for (var i = 0; i < boyut; i++) {
knll.push(knll[i]); // access From
}
Upvotes: 1
Reputation: 507
In your JS
var json = `@Json.Serialize(Model.YourArray)`;
var objects = JSON.parse(json);
console.log(objects);
Upvotes: 1
Reputation: 8459
You can get the array just like this:
var knll = @Html.Raw(Json.Serialize(Model.kanal));
Upvotes: 3