如何使用 JQuery 在 MVC 中删除选中的行
How to Delete checked row in MVC using JQuery
如何使用 jquery 从 asp.net MVC 中的数据库中删除选中的 table 行
这是我的代码,请帮助我 this.I 尝试一下,但这不起作用,如果有人有建议请给我一些。
function saveOrder(data) {
return $.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
url: "/Bill/SaveOrder",
data: data,
success: function (result) {
alert(result);
location.reload();
},
error: function () {
alert("Error!")
}
});
}
var selectedValues = [];
$.each($("#empsToDel"), function () {
selectedValues.push({
ID = $("input:checked").val()
})
});
var data = JSON.stringify({
Delete:selectedValues
});
<table>
<tr>
<th></th>
<th>@Html.DisplayNameFor(model => model.Product.ProductName)</th>
</tr>
@foreach (var item in Model)
{
<tr id="new">
<td><input type="checkbox" class="checkbox" value="@item.ID" name="empsToDel" id="empsToDel" /></td>
<td>@Html.DisplayFor(modelItem => item.Product.ProductName)</td>
</tr>
}
</table>
<input id="saveOrder" type="submit" class="btn btn-default" value="ok" />
这是我的控制器
<table>
<tr>
<th></th>
<th>@Html.DisplayNameFor(model => model.Product.ProductName)</th>
</tr>
@foreach (var item in Model)
{
<tr id="new'@item.ID'">
<td><input type="checkbox" class="checkbox" value="@item.ID"
name="empsToDel" id="empsToDel'@item.ID'" /></td>
<td>@Html.DisplayFor(modelItem => item.Product.ProductName)</td>
</tr>
}
</table>
<input id="saveOrder" type="submit" class="btn btn-default" value="ok" />
$("#saveOrder").click(function ()
{
var selectedValues = new Array();
$(".checkbox:checked").each(function () {
selectedValues.push($(this).val());
});
var clientIdList = selectedValues.join();
$.ajax(
{
type: "POST",
url: '@Url.Action("SaveOrder", "Bill")',
data: { clientIdList: clientIdList },
beforeSend: function () {
},
success: function (response) {
alert(result);
location.reload();
},
complete: function () {
},
error: function () {}
});
});
BillController.cs
public ActionResult SaveOrder( string clientIdList = null)
{
if (clientIdList != "")
{
var clientIds = clientIdList.Split(',').Select(x =>
Int64.Parse(x)).ToArray();
}
}
希望这对您有所帮助。
如何使用 jquery 从 asp.net MVC 中的数据库中删除选中的 table 行 这是我的代码,请帮助我 this.I 尝试一下,但这不起作用,如果有人有建议请给我一些。
function saveOrder(data) {
return $.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
url: "/Bill/SaveOrder",
data: data,
success: function (result) {
alert(result);
location.reload();
},
error: function () {
alert("Error!")
}
});
}
var selectedValues = [];
$.each($("#empsToDel"), function () {
selectedValues.push({
ID = $("input:checked").val()
})
});
var data = JSON.stringify({
Delete:selectedValues
});
<table>
<tr>
<th></th>
<th>@Html.DisplayNameFor(model => model.Product.ProductName)</th>
</tr>
@foreach (var item in Model)
{
<tr id="new">
<td><input type="checkbox" class="checkbox" value="@item.ID" name="empsToDel" id="empsToDel" /></td>
<td>@Html.DisplayFor(modelItem => item.Product.ProductName)</td>
</tr>
}
</table>
<input id="saveOrder" type="submit" class="btn btn-default" value="ok" />
这是我的控制器
<table>
<tr>
<th></th>
<th>@Html.DisplayNameFor(model => model.Product.ProductName)</th>
</tr>
@foreach (var item in Model)
{
<tr id="new'@item.ID'">
<td><input type="checkbox" class="checkbox" value="@item.ID"
name="empsToDel" id="empsToDel'@item.ID'" /></td>
<td>@Html.DisplayFor(modelItem => item.Product.ProductName)</td>
</tr>
}
</table>
<input id="saveOrder" type="submit" class="btn btn-default" value="ok" />
$("#saveOrder").click(function ()
{
var selectedValues = new Array();
$(".checkbox:checked").each(function () {
selectedValues.push($(this).val());
});
var clientIdList = selectedValues.join();
$.ajax(
{
type: "POST",
url: '@Url.Action("SaveOrder", "Bill")',
data: { clientIdList: clientIdList },
beforeSend: function () {
},
success: function (response) {
alert(result);
location.reload();
},
complete: function () {
},
error: function () {}
});
});
BillController.cs
public ActionResult SaveOrder( string clientIdList = null)
{
if (clientIdList != "")
{
var clientIds = clientIdList.Split(',').Select(x =>
Int64.Parse(x)).ToArray();
}
}
希望这对您有所帮助。