简体   繁体   中英

How to convert List in c# to array in javascript .net core

$(document).ready(function () { var imgs = @Model.EditProductImageList.ToArray(); console.log(imgs); });

With the following you can serialize your object into a json and this can be parsed into an array with javascript

So your in your page/view would look like this:

<script type="text/javascript">
    var json = '@Json.Serialize(Model.EditProductImageList)';
    var array = JSON.parse(json);
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM