How do I convert a C# List to a Javascript array?

前端 未结 9 881
情书的邮戳
情书的邮戳 2020-11-27 16:56

I have a datatable that I\'m converting into a List, serializing it and passing it to my view using a viewmodel.

My viewmodel looks like this:

public         


        
9条回答
  •  一生所求
    2020-11-27 17:24

    You could directly inject the values into JavaScript:

    //View.cshtml
    
    

    See JSON.parse, Html.Raw

    Alternatively you can get the values via Ajax:

    public ActionResult GetValues()
    {
        // logic
        // Edit you don't need to serialize it just return the object
    
        return Json(new { Addresses: lAddressGeocodeModel });
    }
    
    
    

    See jQuery.ajax

提交回复
热议问题