2010-12-21 65 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(); 
}