从MVC传递数组的JavaScript? [英] Pass Array from MVC to javascript?

查看:81
本文介绍了从MVC传递数组的JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用此传递从ASP.NET MVC的变量:

I can pass a variable from MVC ASP.NET by using this :

var lastCategoryId = '<%=Model.CS.LastSelectedCategory %>';

这做工精细用字符串或整数,但我怎么做一个字符串数组?我曾尝试通过阵列的方式相同,但变量设置为System.String []?

This work fine with string or integer but how do I do with an array of strings? I have tried to pass the array the same way but the variable is set to System.String[] ?

推荐答案

这应该做的。

var someArray=[<%foreach (var s in myStringArray){%>'<%=s%>',<%}%>];

这篇关于从MVC传递数组的JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆