【发布时间】:2016-06-23 21:06:50
【问题描述】:
您好,我目前正在开发 MVC Razor。这是场景。谁能有解决方案?我在 BeginForm 中有一个网络网格。
@using(Html.BeginForm("AllocationOnlyEdit", "AllocationModel", FormMethod.Post, new {
block = @Model.block
})) {
if (Model != null) {
var grid = new WebGrid(rowsPerPage: Model.RecordsPerPage);
grid.Bind(Model.AllocModelsListView, autoSortAndPage: false, rowCount: Model.NumberOfRecords); < div class = "wrap" >
< div id = "gridContent" >
@grid.GetHtml(
htmlAttributes: new {
id = "gdvsearch"
},
fillEmptyRows: false,
tableStyle: "mGrid",
columns: new [] {
grid.Column(header: null, canSort: false, format: @ < text > < input id = "ChkDelete_@item.AllocId"
onclick = "javascript: DeleteCheckBox(this)"
name = "ChkDelete_@item.AllocId"
class = "delete-chkbox"
type = "checkbox"
value = "@item.AllocId" / > < /text>),
grid.Column("AllocYear", header: "Year", format: @ < input name = "AllocYear_@item.AllocId"
id = "AllocYear"
type = "text"
style = "font-weight:bold;width:50px;"
value = "@item.AllocYear"
disabled = "disabled"
title = "@item.AllocYear"
class = "editY-mode" / > ),
grid.Column("AllocPercentage", header: "Percentage", format: @ < input name = "AllocPercentage_@item.AllocId"
id = "AllocPercentage_@item.AllocId"
type = "text"
style = "font-weight:bold;width:50px;"
value = "@item.AllocPercentage"
disabled = "disabled"
title = "@item.AllocPercentage"
class = "editPer-mode" / > ),
grid.Column("LocationDesc", header: "Location", format: @ < input name = "LocationDesc_@item.AllocId"
id = "LocationDesc_@item.AllocId"
type = "text"
style = "font-weight:bold;width:50px;"
value = "@item.LocationDesc"
disabled = "disabled"
title = "@item.LocationDesc"
class = "editPer-mode" / > )
网格在同一次点击时同时执行多个操作(添加/更新/删除)。因此,下面的 javascript 循环并为要编辑/添加/删除的所有网格行调用 action 方法。
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: '@Url.Action("DeleteAndSaveAtSameTimeModels")',
data: {
"AllocId": AllocId,
"Allocpercentage": Allocpercentage,
"sumtrans": sumtrans,
"tempsumtrancs": tempsumtrancs,
"Location": Location,
"rowCount": rowCount
},
dataType: "json",
beforeSend: function() {},
success: function(data) {
debugger;
tempsumtrancs++;
if (data.sumtrans == tempsumtrancs) {
window.location.href = data.result;
}
}
});
如果要删除3行并添加1行,则应调用动作方法“DeleteAndSaveAtSameTimeModels”4次,然后调用默认路由,即搜索ActionMethod并返回更新的网格。
但它所做的是调用 BeginForm 操作方法“AllocationOnlyEdit”,然后吹走。 action 方法返回,
return Json(new { ok = true, AllocId = AllocId, y = y, newRows = newRows, sumtrans = sumtrans, tempsumtrancs = tempsumtrancs, result = Url.Action("AllocationModelSearch", objAllocationModels) }, JsonRequestBehavior.AllowGet);
【问题讨论】:
标签: json asp.net-mvc-4 c#-4.0 asp.net-ajax