Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

asp.net mvc - jQuery Sort and MVC Stopped Working

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...