如何在 ActionResult 的视图中打开 Kendo Window
How can I open a Kendo Window in a view from an ActionResult
当用户从 kendo 网格添加时,我需要检查现有实体。这很好用。
我坚持的是如果要添加可能的重复项,则在网格顶部显示 Kendo window,并提供合并、添加或取消的选项。
我有一个 DivotAdminController 和它的视图。我添加了一个与 DivotCreate 动作同名的 partialView:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Divots_Create([DataSourceRequest] DataSourceRequest request, Divot divot)
{
using (var context = new DataContext())//Check for Barcode match and ask user what to do if found
{
var existingDivotId = context.Divot
.Include("CategoryLevel1")
.Join(context.Containers, ast => ast.ContainerId, cts => cts.Id, (ast, cts) => new { Divot = ast, Container = cts })
.Where(a => a.Divot.Barcode == divot.Barcode)
.OrderByDescending(a => a.Divot.CaptureDate)
.First().Divot.Id;
var existingDivot = context.Divot.Where(a => a.Id == existingDivotId).FirstOrDefault();
if (existingDivot != null)
{
return PartialView("Divots_Create", existingDivot);
}
}
if (divot != null) //if not a match save the new entry.
{
var containerid = (guid)tempdata["selectcontainerid"];
divot.Id = Guid.NewGuid();
divot.CaptureDate = DateTime.Now;
divot.ModifiedDate = DateTime.Now;
divot.Username = User.Identity.Name;
_repository.AddDivot(divot);
}
return Json(new[] { divot }.ToDataSourceResult(request, ModelState));
}
找到匹配项后,return PartialView("Divots_Create", existingDivot);
行会执行,但客户端不会发生任何事情。
我想知道是否有办法让部分视图显示为模态,或者 kendo window 如果找到重复项则显示为模态?
在您的操作中添加模型错误:
ModelState.AddModelError("", "User name already exists");
为出现错误的网格分配事件处理程序:
.Events(events => events.Error("handleError"))
通过 javascript 函数(显示 window 或其他)处理客户端错误
handleError = function (args) {
if (args.errors) {
var grid = $("#grid").data("kendoGrid");
grid.one("dataBinding", function (e) {
e.preventDefault();
$.each(args.errors, function (propertyName) {
var error = this.errors[0];
});
});
}
};
查看此Blog post了解更多详情
当用户从 kendo 网格添加时,我需要检查现有实体。这很好用。
我坚持的是如果要添加可能的重复项,则在网格顶部显示 Kendo window,并提供合并、添加或取消的选项。
我有一个 DivotAdminController 和它的视图。我添加了一个与 DivotCreate 动作同名的 partialView:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Divots_Create([DataSourceRequest] DataSourceRequest request, Divot divot)
{
using (var context = new DataContext())//Check for Barcode match and ask user what to do if found
{
var existingDivotId = context.Divot
.Include("CategoryLevel1")
.Join(context.Containers, ast => ast.ContainerId, cts => cts.Id, (ast, cts) => new { Divot = ast, Container = cts })
.Where(a => a.Divot.Barcode == divot.Barcode)
.OrderByDescending(a => a.Divot.CaptureDate)
.First().Divot.Id;
var existingDivot = context.Divot.Where(a => a.Id == existingDivotId).FirstOrDefault();
if (existingDivot != null)
{
return PartialView("Divots_Create", existingDivot);
}
}
if (divot != null) //if not a match save the new entry.
{
var containerid = (guid)tempdata["selectcontainerid"];
divot.Id = Guid.NewGuid();
divot.CaptureDate = DateTime.Now;
divot.ModifiedDate = DateTime.Now;
divot.Username = User.Identity.Name;
_repository.AddDivot(divot);
}
return Json(new[] { divot }.ToDataSourceResult(request, ModelState));
}
找到匹配项后,return PartialView("Divots_Create", existingDivot);
行会执行,但客户端不会发生任何事情。
我想知道是否有办法让部分视图显示为模态,或者 kendo window 如果找到重复项则显示为模态?
在您的操作中添加模型错误:
ModelState.AddModelError("", "User name already exists");
为出现错误的网格分配事件处理程序:
.Events(events => events.Error("handleError"))
通过 javascript 函数(显示 window 或其他)处理客户端错误
handleError = function (args) {
if (args.errors) {
var grid = $("#grid").data("kendoGrid");
grid.one("dataBinding", function (e) {
e.preventDefault();
$.each(args.errors, function (propertyName) {
var error = this.errors[0];
});
});
}
};
查看此Blog post了解更多详情