in asp.net mvc, how can I pass an array of integers as a parameter

后端 未结 2 1623
无人及你
无人及你 2021-01-12 14:21

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 o

2条回答
  •  情深已故
    2021-01-12 14:43

    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) {
            // ...
        }
    });
    

提交回复
热议问题