【问题标题】:jQuery Sort and MVC Stopped WorkingjQuery 排序和 MVC 停止工作
【发布时间】:2010-12-21 02:51:21
【问题描述】:

当 JQuery Sort 调用我的排序操作时,我收到以下错误:

参数字典包含方法“System.Web.Mvc.EmptyResult SortDonations(System.Collections.Generic.List1[System.Int32])' in 'Vol.Web.Areas.ActivityArea.Controllers.DonationController'. The dictionary contains a value of type 'System.Collections.Generic.List1[Vol.Models.Token]”的参数“DonationIDS”的无效条目,但参数需要“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();
        }

它工作得很好,但现在它似乎引用了另一个类,Token。任何想法发生了什么或从哪里开始寻找?

【问题讨论】:

    标签: jquery asp.net-mvc jquery-ui-sortable


    【解决方案1】:

    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();
    }
    

    【讨论】:

      【解决方案2】:

      只需将以下内容添加到 global.asax Application_Start 方法中

      ModelMetadataProviders.Current = new DataAnnotationsModelMetadataProvider();
      

      有关这方面的更多信息,请参阅 Scott 的博客:http://weblogs.asp.net/scottgu/archive/2010/12/14/update-on-asp-net-mvc-3-rc2-and-a-workaround-for-a-bug-in-it.aspx

      【讨论】:

        猜你喜欢
        • 2012-03-30
        • 2012-07-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-06
        • 2011-01-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多