12
Ho il seguente:Come posso inviare assegnare un elenco <string> a un array JavaScript o un oggetto enumerabile
ViewBag.SomeEnumerable = new List<string>() { "string1", "string2" };
Ora come faccio ad assegnare ViewBag.SomeEnumerable
a un array
o una qualche forma di oggetto enumerabile sul lato JavaScript? es:
function SomeFunction()
{
var array = @ViewBag.SomeEnumerable;
for(var eachItem in array)
{
alert(eachItem); // should display "string1" then string2"
}
}
VS dà 'errore di sintassi a;' quando dichiaro var matrice = @ Html.Raw (Json.Encode (ViewBag.SomeEnumerable)); comunque o/p è corretto in html reso nel browser –
@IshaanPuniani, perché ti fidi anche di VS Intellisense? È sbagliato. Guarda il markup reso per vedere che è corretto nonostante VS ti dica che è sbagliato. –