我有一个控制器函数,以前将整数作为 URL 中的每个部分(我在路由文件中设置),但现在其中一个参数需要是整数数组。这是控制器的操作:
public JsonResult Refresh(string scope, int[] scopeId)
{
return RefreshMe(scope, scopeId);
}
在我的 javascript 中,我有以下内容,但我现在需要将scopeId 设为整数数组。
我如何设置一个 url 来使用 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();
}
以下应该完成这项工作:
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) {
// ...
}
});
如果您使用 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) {
// ...
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)