1:首先需要在前端显示界面View视图中添加查询按钮:
<div> <div>@Html.NopLabelFor(model => model.IndividualName) </div>
<div>@Html.NopEditorFor(model => model.IndividualName)</div>
<input type="button" id="search-name" value="@T("查询")"/>
</div>
2:然后为查询添加function:
<script type="text/javascript"> $(document).ready(function() { //search button $('#search-name').click(function() { var grid = $('#enterprise-grid').data('kendoGrid'); grid.dataSource.page(1); return false; }); $("#@Html.FieldIdFor(model=>model.IndividualName)").keydown(function(event) { if (event.keyCode === 13) { $("#search-name").click(); return false; } }); }) function additionalData() { var data = { key: $('#@Html.FieldIdFor(model => model.IndividualName)').val()//通过关键字key }; addAntiForgeryToken(data); return data; } </script>
注意此时的additionalData在json请求数据时获得的数据集(包含key的)
3:在控制器端的方法中接收并使用:
public ActionResult List(DataSourceRequest command, string key = "") { var Individuals = _individualInfoService.GetAllIndividualInfos().Where(x => x.IndividualName.Contains(key)).ToList();//通过关键字匹配 }