我目前正在开发一个具有 CRUD 功能的网站。在添加、编辑或删除成功完成后,我正在使用下面的 javascript 代码显示一条消息。
function addSuccess(data) {
if (data.Success == true) {
$('#addDialog').dialog('close');
$('#commonMessage').html("Process Complete");
$('#commonMessage').delay(400).slideDown(400).delay(3000).slideUp(400);
}
else {
$("#add-message").html(data.ErrorMessage);
$("#add-message").show();
}
}
但是,我在包含 webGrid 的局部视图上呈现结果。在这种情况下,产品的表格列表位于此部分视图中。在(假设)编辑过程完成后,我希望编辑的字段在编辑对话框关闭后反映。我的问题是,我不知道如何在不影响整个页面的情况下刷新局部视图。
有人可以指出我这样做的好方法吗?非常感谢你!
编辑:
下面是我如何将项目添加到我的网格。请注意,整个代码都在我的 PartialView 中。谢谢!
@{
MyStore.Business.Manager.ProductsManager repository = new MyStore.Business.Manager.ProductsManager ();
List<MyStore.Data.Products> ProductsList = repository.GetAllProducts(ViewData["StoreCode"].ToString());
var grid = new WebGrid(ProductsList );
grid.Pager(WebGridPagerModes.All);
@grid.GetHtml(tableStyle: "webGrid",
htmlAttributes: new { id = "DataTable" },
headerStyle: "header",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("ProductCode", style: "width: 400px;"),
grid.Column("Name", style: "width: 400px"),
grid.Column("Price", style: "width: 100px;"),
grid.Column("", format: @<text>@Html.ActionLink("Edit", "_Edit", new { RecordID = item.RecordID }, new { @class = "editLink" })</text>, style: "width: 100px"),
grid.Column("", format: @<text>@Html.ActionLink("Delete", "_Delete", new { RecordID = item.RecordID }, new { @class = "editLink" })</text>, style: "width: 100px")
));
}