如果 e.filter 为空(HTML Razor 语法),如何停止对控制器的读取调用

How to stop read call to controller if e.filter is null (HTML Razor syntax)

虽然 Kendo 网格开发(使用 HTML Razor 语法、MVC、Jquery 和 JavaScript)如果我的过滤器是空的我不想调用控制器或读取数据。我该怎么做? 这是我的代码片段 Razor 代码片段--

 Read(read => read.Action("Action", "Controller").Data("getFilters"))

JS代码

 getFilters= function (e) 
{
 if (e.filter  === null)
 //do nothing and stop
 else 
 return { filters }
}

感谢帮助。

提前致谢。

您可以在 DataSource 的 RequestStart 事件中停止请求:

function requestStart(e) {
    if (!this.filter()) {
        e.preventDefault();
    }
}

您可能希望扩展此代码段以通知用户由于过滤器为空而未加载新数据。否则,用户可能会感到困惑,为什么如果他提交了一个空过滤器,结果却没有改变。

这是我的做法

为过滤器添加事件

Filter("onFiltering")

JS代码

function onFiltering()
{
     if (e.filter === null)
      {
       e.preventDefault();
       //display pop up for confirmation that no filters are applied and user still want to continue please select Yes
       //if Yes then 
       
       $("#Grid").data("kendoGrid").dataSource.read()
       
      }
  }

谢谢大家,感谢你们 answers/comments。

编码愉快