【问题标题】:How can I open a Kendo Window in a view from an ActionResult如何从 ActionResult 的视图中打开 Kendo 窗口
【发布时间】:2015-03-05 08:48:42
【问题描述】:

当用户从剑道网格添加时,我需要检查现有实体。这工作正常。
如果要添加可能的重复项,我会在网格顶部显示一个 Kendo 窗口,并提供合并、无论如何添加或取消的选项。

我有一个 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); 行将执行,但客户端没有任何反应。
我想知道是否有办法让部分视图显示为模态,或者如果找到重复项,剑道窗口显示为模态?

【问题讨论】:

    标签: c# asp.net-mvc-4 razor kendo-ui


    【解决方案1】:

    在您的操作中添加模型错误:

    ModelState.AddModelError("", "User name already exists");
    

    为发生错误的网格分配事件处理程序:

    .Events(events => events.Error("handleError"))
    

    通过 javascript 函数(显示窗口或其他)在客户端处理错误

        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了解更多详情

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多