2016-05-24 29 views
2

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

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

return Json(ModelState.ToDataSourceResult()); 

回答

0

您可以使用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 
    } 
}