Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Pass c# array to javascript array in razor file ...

$
0
0

Hi everyone, I need someone to explain me how to pass the strings of an array, obtained in server-side c #, in a javascript array of strings inside a razor file. I am developing in ASP.NET core MVC. I'm crazy, it looks like a simple thing, following what I've tried to do:

@{

 string[] fieldsList = ViewData["FieldsList"] as string[];

@}

<script>

var fields_list = [];
fields_list = new Array();

function fields_List()     {
       @for (int fld = 0; fld < fieldsList.Length; fld++) {
            @:var field_tmp = @fieldsList[fld];
            @:fields_list.push(field_tmp);
        }
}</script>

Paolo


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>