2010-12-21 75 views
0

我收到以下错误,当JQuery的排序叫我的行动类别:jQuery的排序和MVC停止工作

参数字典包含参数无效输入“DonationIDS”的方法“System.Web.Mvc.EmptyResult SortDonations (System.Collections.Generic.List 1[System.Int32])' in 'Vol.Web.Areas.ActivityArea.Controllers.DonationController'. The dictionary contains a value of type 'System.Collections.Generic.List 1 [Vol.Models.Token]',但该参数需要类型'System.Collections.Generic.List`1 [System.Int32]'的值。
参数名称:参数

的jQuery:

$("#dlist").sortable({ 
     handle: '.sorthandle', 
     update: function() { 
      var order = $('#dlist').sortable('toArray'); 
      $.ajax({ 
       url: '/activity/donation/sortdonations', 

       data: { DonationIDS: order }, 
       type: 'POST', 
       traditional: true 
      }); 
     } 
    }); 

提交值:

Parametersapplication/x-www-form-urlencoded 
DonationIDS 1 
DonationIDS 8 
Source 
DonationIDS=1&DonationIDS=8 

MVC操作:

public EmptyResult SortDonations(List<int> DonationIDS) 
     { 


      int order = 0; 
      foreach (int i in DonationIDS) 
      { 
       donationRepository.UpdateSortOrder(i, order); 
       order++; 
      } 


      return new EmptyResult(); 
     } 

这是工作完美,但现在看来引用另一个类,令牌。任何想法正在发生什么或从哪里开始寻找?

回答

0

enter code here我改变了行动来使用一个字符串,它解决了问题。

 [HttpPost] 
     public EmptyResult SortDonations(string[] donationorder) 


{ 

    int order = 0; 
    foreach (var i in donationorder) 
    { 
     donationRepository.UpdateSortOrder(Convert.ToInt32(i), order); 
     order++; 
    } 


    return new EmptyResult(); 
}