2012-09-12 15 views

Respuesta

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> 

será mostrado como:

<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 está dando 'error de sintaxis en;' cuando i declaro array var = @ Html.Raw (Json.Encode (ViewBag.SomeEnumerable)); sin embargo, o/p es correcto en html representado en el navegador –

+2

@IshaanPuniani, ¿por qué confía en VS Intellisense? Está mal. Mire el marcado prestado para ver si es correcto a pesar de que VS le dice que está equivocado. –

Cuestiones relacionadas