jQuery Sort and MVC Stopped Working

梦想与她 提交于 2019-12-12 05:29:35

问题


I am getting the following error when JQuery Sort calls my sort action:

The parameters dictionary contains an invalid entry for parameter 'DonationIDS' for method '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]', but the parameter requires a value of type 'System.Collections.Generic.List`1[System.Int32]'.
Parameter name: parameters

jQuery:

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

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

Post Values:

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

MVC Action:

 public EmptyResult SortDonations(List<int> DonationIDS)
        {


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


            return new EmptyResult();
        }

It was working perfectly but now it seems to reference another class, Token. Any ideas what is going on or where to start looking?


回答1:


enter code hereI changed by action to use a string and it resolved the issue.

     [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:


Just add the following to the global.asax Application_Start method

ModelMetadataProviders.Current = new DataAnnotationsModelMetadataProvider();

For more on this, see Scott's blog: 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



来源:https://stackoverflow.com/questions/4495896/jquery-sort-and-mvc-stopped-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!