-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
开发工具与关键技术:vs c#
作者: xqll
撰写时间:2019/8/17
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在日常编程中,我们离不开查询新增修改删除,其中用到的最多就是查询了
下面我来演示一下模糊查询
function reloadAll() {
var SearchKeyWord = $("#SearchKeyWord").val();
if (SearchKeyWord == undefined) {
TabSupplier = "";
}
TabSupplier = layuiTable.reload("SalestabTitles", {
url: "/Customersupplier/SuppomerqueryAll",
where: {
SearchKeyWord: SearchKeyWord
}
});
}
其中reloadAll()是搜索按钮的点击事件 SearchKeyWord是要输入查询条件的文本框
判断 如果SearchKeyWord等于undefined的时候 就让它本身为空
接下来我们需要用到表格渲染,然后在表格渲染中利用where来进行对控制器传参数,
之后就是在控制器接收它传过来的参数
public ActionResult SuppomerqueryAll(LayuiTablePage layuiTablePage, string SearchKeyWord)
当然 接收是在查询方法里面接收

之后的话设置一下它查询的条件
if (!string.IsNullOrEmpty(SearchKeyWord))
{
listSup = listSup.Where(m => m.SupplierNumber.Contains(SearchKeyWord) ||
m.SupplierName.Contains(SearchKeyWord) || m.Note.Contains(SearchKeyWord) || m.SupplierPhone.Contains(SearchKeyWord)).ToList();
}
内容就是说 如果SupplierNumber、SupplierName、Note、SupplierPhone字段中的内容有跟文本框条件内容一样的都可以查询到它一整条的数据
接下来我们来测试一下

它的内容是这样的
然后我在条件框里面随便输入点东西再让它查询一遍

比如说 我输入洛 然后它就会在SupplierNumber、SupplierName、Note、SupplierPhone字段中 只要有洛这个字的 那么它一整条数据都会被查询出来

被折叠的 条评论
为什么被折叠?



