【发布时间】:2014-02-12 09:25:57
【问题描述】:
我的页面中有一个剑道 UI 网格。下面是带有 CRUD 数据源操作的 kendo UI 网格代码。
@(Html.Kendo().Grid<Gts.GlaspacLX.Web.ViewModel.ProductViewModel>()
.Name("xyzGrid")
.Columns(columns =>
{
columns.Bound(p => p.SelectedProductCategory).EditorTemplateName("_ProductDropDownList").Title("Product Category").HtmlAttributes(new { @tabindex = "8" });
columns.Bound(p => p.Name).Width(130).Title("% Off").HtmlAttributes(new { @tabindex ="9" });
columns.Bound(p => p.Rate).Width(130).HtmlAttributes(new { @class = "prodDiscRtAlign",@tabindex= "10" });
columns.Bound(p => p.Hours).Width(130).HtmlAttributes(new { @class = "prodDiscRtAlign",@tabindex= "11" });
if (SiteContext.CurrentUser.HasPrivilege(PrivilegeNames.Maintenance, PermissionNames.DELETE))
{
columns.Command(command => { command.Destroy(); }).Width(110).Title("Delete").HtmlAttributes(new { @tabindex = "12" });
}
})
.ToolBar(commands =>
{
commands.Create();
commands.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
.Sortable()
.Navigatable()
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model =>
{
model.Id(p => p.ProductID);
model.Field(p => p.SelectedProductCategory).DefaultValue(ViewBag.DefaultProductCategory);
})
.Read(read => read.Action("Product_Read", "ProductController"))
.Update(update => update.Action("Product_Update", " ProductController "))
.Create(create => create.Action("Product_Create", " ProductController "))
.Destroy(update => update.Action("Product_Destroy", " ProductController ")
))
.Events(e => e.Edit("proField").DataBound("boundProductChange"))
)
下面是剑道网格后“保存”按钮的屏幕截图。它负责页面的任何创建/更新操作。
我的问题是,一旦我单击保存按钮进行任何创建或更新操作,它就会两次发布操作方法。您可以看到上面屏幕截图的控制台。
下面是我的控制器动作方法的一段代码:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Product_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductViewModel> product){
return Json(results.ToDataSourceResult(request, ModelState));
}
下面是proField功能代码:-
function proField(e) {
var defaultproduct = $("#DefaultProductCategory").val();
defaultproduct = "\n" + defaultproduct + "select ";
if (e.model.SelectedProductCategory == "Default" && (e.sender._editContainer[0].textContent == defaultproduct || e.sender._editContainer[0].textContent == "\n select ")) {
e.sender._editContainer[0].disabled = true;
e.sender._editContainer[0].children[0].textContent = "Default";
e.sender.table[0].rows[1].cells[1].click();
e.sender.table[0].rows[1].cells[4].disabled = true;
}
}
【问题讨论】:
-
你能分享
proField函数的代码吗? -
@EfrainReyes 我添加了 proField 功能。
-
你能不能也分享一下“boundProductChange”
-
@Pawan 我仍然看不出代码有问题。你能分享整个视图/布局吗?
-
嘿,我知道这是旧的,但我有一个非常相似的问题。您是否设法弄清楚发生了什么?
标签: asp.net-mvc-4 post kendo-ui grid crud