在asp.net mvc的,我怎么能传递一个整数数组作为参数 [英] in asp.net mvc, how can I pass an array of integers as a parameter
问题描述
我有一个控制器功能previously有整数作为URL每个部分(我设置在路由文件),但现在的参数之一需要是一个整数数组。下面是控制器的动作:
公共JsonResult刷新(串范围,INT [] scopeId)
{
返回RefreshMe(范围,scopeId);
}
在我的javascript,我有下面的,但我现在需要得到scopeId是一个整数数组。 我怎样才能设置一个URL张贴到使用jQuery JavaScript的
VAR范围=测试;
VAR scopeId = 3;
// SCOPEID现在需要一个整数数组
.post的$('/日历/刷新/+范围+/+ scopeId,功能(数据){
$(replacementHTML)html的(数据);
$(blockSection).unblock();
}
下面应该做的工作:
VAR范围='测试';
变种scopeId = [1,2,3];
$阿贾克斯({
网址:@ Url.Action(刷新,日历),
键入:POST,
数据:{适用范围:适用范围,scopeId:scopeId},
传统:真正的,
成功:函数(结果){
// ...
}
});
如果你正在使用ASP.NET MVC 3,你也可以发送请求作为一个JSON对象:
$。阿贾克斯({
网址:@ Url.Action(刷新,日历),
键入:POST,
的contentType:应用/ JSON的;字符集= UTF-8,
数据:JSON.stringify({适用范围:适用范围,scopeId:scopeId}),
成功:函数(结果){
// ...
}
});
i have a controller function that previously had integers as each section in the URL (which i setup in the routing file) but now one of the parameters needs to be an array of integers. Here is the controller action:
public JsonResult Refresh(string scope, int[] scopeId)
{
return RefreshMe(scope, scopeId);
}
in my javascript, i had the below but i now need to get scopeId to be an integer array. how can i setup up a url to post to using jquery, javascript
var scope = "Test";
var scopeId = 3;
// SCOPEID now needs to be an array of integers
$.post('/Calendar/Refresh/' + scope + '/' + scopeId, function (data) {
$(replacementHTML).html(data);
$(blockSection).unblock();
}
The following should do the job:
var scope = 'Test';
var scopeId = [1, 2, 3];
$.ajax({
url: '@Url.Action("Refresh", "Calendar")',
type: 'POST',
data: { scope: scope, scopeId: scopeId },
traditional: true,
success: function(result) {
// ...
}
});
and if you are using ASP.NET MVC 3 you could also send the request as a JSON object:
$.ajax({
url: '@Url.Action("Refresh", "Calendar")',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ scope: scope, scopeId: scopeId }),
success: function(result) {
// ...
}
});
这篇关于在asp.net mvc的,我怎么能传递一个整数数组作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!