jQuery排序和MVC停止工作
当JQuery Sort调用我的排序操作时,我遇到以下错误: 参数字典包含“Vol.Web.Areas.ActivityArea.Controllers.DonationController”中方法“System.Collections.Generic.ListjQuery排序和MVC停止工作,jquery,asp.net-mvc,jquery-ui-sortable,Jquery,Asp.net Mvc,Jquery Ui Sortable,当JQuery Sort调用我的排序操作时,我遇到以下错误: 参数字典包含“Vol.Web.Areas.ActivityArea.Controllers.DonationController”中方法“System.Collections.Generic.List1[System.Int32])的参数“DonationId”的无效条目。字典包含类型为“System.Collections.Generic.List”的值,但该参数需要类型为“System.Collections.Generic.Li
1[System.Int32])的参数“DonationId”的无效条目。字典包含类型为“System.Collections.Generic.List”的值,但该参数需要类型为“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();
}
public EmptyResult排序国家(列出捐赠)
{
整数阶=0;
foreach(捐赠中的int i)
{
donationRepository.updatesortororder(i,order);
订单++;
}
返回新的EmptyResult();
}
它工作得很好,但现在它似乎引用了另一个类Token。你知道发生了什么或从哪里开始查找吗?在此处输入代码
我通过操作更改为使用字符串,它解决了问题
[HttpPost]
public EmptyResult SortDonations(string[] donationorder)
{
int order = 0;
foreach (var i in donationorder)
{
donationRepository.UpdateSortOrder(Convert.ToInt32(i), order);
order++;
}
return new EmptyResult();
}
只需将以下内容添加到global.asax应用程序\u Start方法
ModelMetadataProviders.Current = new DataAnnotationsModelMetadataProvider();
有关这方面的更多信息,请参阅Scott的博客: