我目前正在开发一个带有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的部分视图中呈现结果。在这种情况下,产品的表格列表在此部分视图中。完成(假设)编辑过程后,我希望在编辑对话框关闭后反映出编辑的字段。我的问题是,我不知道如何在不影响整个页面的情况下刷新局部视图。
请问有没有人能指点一种好的方法来实现这个功能?非常感谢!
编辑:
以下是我添加项目到网格的方式。请注意,这整段代码都在我的部分视图中。谢谢!
@{
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")
));
}
GetProducts
和Items
部分?我好像不太明白。谢谢!!! - SmileyGetProducts
是Items控制器中返回Product列表以绑定WebGrid的方法的名称?如果是这样的话,那我必须说我不是用那种方式做的。请参见我上面的编辑。谢谢!:) - Smiley