1👍
✅
You can open the developer tools and you should see this error:
This is because you call the code of C# in js, what you actually fill in the array is a variable, not a string:
You can add quotes to convert it to a string:
@if (TempData["success"] != null)
{
foreach (var item in ViewBag.States)
{
if (item == "completed")
{
@:completed.push('@item');
}
else if (item == "no-answer")
{
@:no_answer.push('@item');
}
else if (item == "busy")
{
@:busy.push('@item');
}
else if (item == "failed")
{
@:failed.push('@item');
}
}
}
Test Result:
Source:stackexchange.com