【问题标题】:Custom success messages in Kendo grid剑道网格中的自定义成功消息
【发布时间】:2016-05-24 20:09:41
【问题描述】:

我想在我的 Kendo 网格中成功更新记录时返回不同的成功消息(内联编辑)。我想做的是这样的(返回类似于 ModelState.AddModelError 的弹出窗口,仅作为成功消息)。我知道 ModelState 没有“成功”的等价物,所以我想知道如何实现这一点。

if (MyBool == true)
{
  //custom message one
}
else
{
  //custom message two
}

return Json(ModelState.ToDataSourceResult());

【问题讨论】:

    标签: kendo-grid modelstate


    【解决方案1】:

    您可以使用DataSource的requestEnd事件来检查当前操作是“创建”还是“更新”并且没有错误提醒用户。

    示例 MVC 包装器

    @(Html.Kendo().Grid<ProductViewModel>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.ProductName).Title("Product Name");
            columns.Bound(p => p.UnitPrice).Title("Unit Price");
            columns.Bound(p => p.UnitsInStock).Title("Units In Stock");
        })
        .Pageable()
        .Sortable()
        .DataSource(dataSource => dataSource
            .Ajax()
            // below is the RequestEnd event handler 
            .Events(events => events.RequestEnd("onRequestEnd"))        
            .Read(read => read.Action("Products_Read", "Grid"))
         )
    )
    

    这里是事件处理程序

    function onRequestEnd(e) {        
        if (e.type == "update" && !e.response.Errors) {
           // Update record is successfull, show your desired message
        }
    
        if (e.type == "create" && !e.response.Errors) {
           // Create record is successfull, show your desired message
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-09-28
      • 1970-01-01
      • 2014-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2013-11-26
      • 1970-01-01
      相关资源
      最近更新 更多