ajax call passing empty array to controller

ajax call passing empty array to controller

 

Ajax passing empty value but Controller get null in ASP.NET MVC

 

Pass array to mvc Action via AJAX

回答1

Set the traditional property to true before making the get call. i.e.:

jQuery.ajaxSettings.traditional = true

$.get('/controller/MyAction', { vals: arrayOfValues }, function (data) {... 

 

回答2

I have had issues in the past when attempting to perform a POST (not sure if that is exactly what you are doing, but I recall when passing an array in, traditional must be set to true.

 var arrayOfValues = new Array();

 //Populate arrayOfValues 
 $.ajax({ 
      type: "POST",
      url: "<%= Url.Action("MyAction","Controller")%>",
      traditional: true,
      data: { 'arrayOfValues': arrayOfValues }              
 });
posted @ 2020-12-30 11:42  ChuckLu  阅读(115)  评论(0编辑  收藏  举报