leo*_*ora 6 arrays ajax asp.net-mvc jquery
我有一个控制器函数,以前有整数作为URL中的每个部分(我在路由文件中设置)但现在其中一个参数需要是一个整数数组.这是控制器动作:
public JsonResult Refresh(string scope, int[] scopeId)
{
return RefreshMe(scope, scopeId);
}
Run Code Online (Sandbox Code Playgroud)
在我的javascript中,我有以下但我现在需要将scopeId作为整数数组.我如何设置一个网址发布到使用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();
}
Run Code Online (Sandbox Code Playgroud)
Dar*_*rov 12
以下应该做的工作:
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) {
// ...
}
});
Run Code Online (Sandbox Code Playgroud)
如果您使用的是ASP.NET MVC 3,您还可以将请求作为JSON对象发送:
$.ajax({
url: '@Url.Action("Refresh", "Calendar")',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ scope: scope, scopeId: scopeId }),
success: function(result) {
// ...
}
});
Run Code Online (Sandbox Code Playgroud)