Create variables in Razor and then manipulate them in Jquery?

3

Is it possible to do something like this?

@{var list = [1,2,3,4,5]; }

I do not boot error but then when I want to use that variable in Jquery, it does not appear.

What is the correct way to do it?

    
asked by Necroyeti 14.12.2017 в 22:35
source

1 answer

2

It is possible to scroll through the list in the javascript array

<script type="text/javascript">

    var list = [1,2,3,4,5];

    @foreach (var d in list)
    {
        @:myArray.push("@d");
    }

    alert(myArray);

</script>
    
answered by 14.12.2017 / 22:51
source