使用 mvc5 隐藏 webgrid 中的行
你的视图应该有以下部分 -
var grid = new WebGrid(
ajaxUpdateContainerId: "grid");
grid.Bind(data);
grid.Pager(WebGridPagerModes.All);
@grid.GetHtml(htmlAttributes: new { id = "grid" }, // id for ajaxUpdateContainerId parameter
fillEmptyRows: false,
tableStyle: "webgrid-table",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style",
mode: WebGridPagerModes.All,
columns: grid.Columns(
grid.Column("Container_No", "Container No", canSort: false),
grid.Column("SizeText", "SizeList", canSort: false),
grid.Column("ContainerText", "Container Type", canSort: false),
grid.Column("CargoText", "Cargo Type", canSort: false),
grid.Column(header: "Action", canSort: false, style: "col-lg-2",
format: @<text>
@Html.Raw("<a href='#' id='" + item.Container_No + "' onclick='goDelete(id);'><span class='glyphicon glyphicon-trash'> </span></a>")
请在您的脚本中包含以下函数--
function goDelete(data) {
$(".page-loader-wrapper").show();`enter code here`
if (confirm("Are you sure to delete this Container Entry?")) {
$.ajaxSetup({ cache: false });
$.ajax({
type: "POST",
url: "/ControllerName/ActionName",
data: '{Container_No: ' + data + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$("#" + data).parents("tr").remove();
$(".page-loader-wrapper").hide();
alert(data + "Container removed successfully !!");
}
});
}
}