jquery – 如何通过ajax将集合/数组发送到mvc操作

前端之家收集整理的这篇文章主要介绍了jquery – 如何通过ajax将集合/数组发送到mvc操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
atm我正在尝试这样,但没有运气,我的Do行动无效
  1. var arr = [31,17,16];
  2.  
  3. $.get('<%=Url.Action("Do","Foo") %>',{ids:arr},function(d){...});
  4.  
  5. public ActionResult Do(IEnumerable<int> ids)
  6. {
  7. ...
  8. }

解决方法

试试这样:
  1. $.ajax({
  2. url: '<%= Url.Action("Do",data: { ids: [ 31,16] },traditional: true,success: function(result) {
  3.  
  4. }
  5. });

注意traditional: true参数.

或者如果你坚持使用$.get()函数

  1. $.get(
  2. '<%= Url.Action("Do",$.param({ ids: [31,true),function (result) {
  3.  
  4. }
  5. );

猜你在找的jQuery相关文章