jQuery的排序和MVC停止工作 [英] jQuery Sort and MVC Stopped Working
问题描述
我收到以下错误,当JQuery的排序叫我的排序动作:
I am getting the following error when JQuery Sort calls my sort action:
参数词典共包含参数法System.Web.Mvc.EmptyResult SortDonations(System.Collections.Generic.List 1 [System.Int32])'中的无效条目DonationIDS'' Vol.Web.Areas.ActivityArea.Controllers.DonationController。该字典包含类型的值'System.Collections.Generic.List
1 [Vol.Models.Token]',但参数需要的类型System.Collections.Generic.List`1值' [System.Int32]结果参数名:参数
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.List
1[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
});
}
});
邮政值:
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();
}
这是完全工作,但现在看来引用另一个类,令牌。任何想法是怎么回事,或从哪里开始寻找?
It was working perfectly but now it seems to reference another class, Token. Any ideas what is going on or where to start looking?
推荐答案
只需添加以下在Global.asax的Application_Start方法
Just add the following to the global.asax Application_Start method
ModelMetadataProviders.Current = new DataAnnotationsModelMetadataProvider();
有关更多相关信息,请参阅斯科特的博客:<一href=\"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\" rel=\"nofollow\">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
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
这篇关于jQuery的排序和MVC停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!