我目前正在開發一個具有CRUD功能的網站。在添加,編輯或刪除成功完成後,我正在使用以下JavaScript代碼來顯示消息。MVC 4僅刷新局部視圖
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而不影響整個頁面。
有人可以請我指出一個很好的方法來做到這一點?非常感謝你!
編輯:
下面是我如何將項目添加到我的網格。請注意,這整個代碼都在我的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")
));
}
嗨!感謝您的迴應!你能解釋一下'GetProducts'和'Items'部分嗎?我似乎沒有得到它。謝謝!!! – Smiley 2012-07-16 02:33:59
這是否意味着'GetProducts'是來自'Items'控制器的方法的名稱,它返回一個ListofProducts以綁定到webGrid?因爲如果確實如此,那麼我必須說我不是那樣做的。請參閱我上面的編輯。謝謝! :) – Smiley 2012-07-16 02:39:18