【问题标题】:Is it possible to convert a MVC C# List<int> to an javascript array?是否可以将 MVC C# List<int> 转换为 javascript 数组?
【发布时间】:2015-03-14 07:48:12
【问题描述】:

是否可以将 MVC C# 列表转换为 javascript 数组?

var jsArray = @Model.IntList;

任何帮助将不胜感激。

【问题讨论】:

标签: javascript c# json asp.net-mvc


【解决方案1】:

你可以的

<script type="text/jscript">
  var jsonVariable = @(Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.IntList)));//using Newtonsoft
//or you can use below
//var jsonVariable = @Html.Raw(Json.Encode(Model.IntList))
</script>

【讨论】:

【解决方案2】:

您可以使用以下方法将 @Model.IntList 转换为 javascript 数组

<script type="text/jscript">
  var array = @Html.Raw(Json.Encode(Model.IntList))
</script>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多