2012-09-12 8 views

risposta

30
<script type="text/javascript"> 
function SomeFunction() { 
    var array = @Html.Raw(Json.Encode(ViewBag.SomeEnumerable)); 
    for(var i = 0; i < array.length; i++) { 
     alert(array[i]); // should display "string1" then string2" 
    } 
} 
</script> 

saranno resi come:

<script type="text/javascript"> 
function SomeFunction() { 
    var array = ["string1","string2"]; 
    for(var i = 0; i < array.length; i++) { 
     alert(array[i]); // should display "string1" then string2" 
    } 
} 
</script> 
+0

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 –

+2

@IshaanPuniani, perché ti fidi anche di VS Intellisense? È sbagliato. Guarda il markup reso per vedere che è corretto nonostante VS ti dica che è sbagliato. –

Problemi correlati