在asp.net mvc中,如何将整数数组作为参数传递

我有一个控制器函数,以前有整数作为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) { // ... } }); 

以下是来自jquery API for $ .post()的示例

示例:将数据数组传递给服务器(同时仍然忽略返回结果)。

 $.post("test.php", { 'choices[]': ["Jon", "Susan"] }, function() { //do stuff });