如何使用删除请求与Ajax Mvc删除多行被选中
问题描述:
我想删除已检查过的html表上的多行我不想使用post方法。如何发送Id阵列发送Controller.I使用EF6 感谢帮助。如何使用删除请求与Ajax Mvc删除多行被选中
$.ajax({
url: "/Urun/DeleteField" + '/' + DeleteArray,
type: "DELETE",
dataType: "JSON",
data: JSON.stringify(DeleteArray),
cache: false,
success: function(node) {
if (node.success) {
alert("İşlem Başarılı");
} else alert("İşlem Başarısız");
}
});
while (DeleteArray.length > 0) {
DeleteArray.pop();
}
答
在服务器端:
[HttpDelete]
public JsonResult TestDelete(List<int> Ids)
{
//your businbes logic goes here
return Json(new { success = true}); //return example
}
在客户端:
var DeleteArray = [1, 2, 3, 4]; //your array example
$.ajax({
url: "@Url.Action("TestDelete","Home")", // create urls properly
type: "DELETE",
dataType: 'json',
contentType: "application/json, charset=utf-8",
data: JSON.stringify({ Ids: DeleteArray }),
cache: false,
success: function (node) {
if (node.success) {
alert("Success"); //your success callback logic goes here
} else alert("Fail");
}
});
答
我有固定与此线在web.config中......
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>`
哪一部分不清楚你?客户端或服务器?同样,使用'DeleteArray.pop();代码块'将会更好地放置在你的ajax调用的成功回调中。 – aleha 2014-12-08 09:10:52
服务器端。我不能发送参数到我的DeleteField方法。 – Namaste00 2014-12-08 09:52:57