Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 筛选功能在ASP.NET MVC中不起作用_C#_Entity Framework_Linq - Fatal编程技术网

C# 筛选功能在ASP.NET MVC中不起作用

C# 筛选功能在ASP.NET MVC中不起作用,c#,entity-framework,linq,C#,Entity Framework,Linq,在asp.NETMVC中,我试图对一个表进行文件管理,但它不起作用 在我的控制器方法中: public ActionResult Index(string sortOrder, string searchString) { var employeesSearch = from s in db.Employees select s; if (!String.IsNullOrEmpty(searchString)) {

在asp.NETMVC中,我试图对一个表进行文件管理,但它不起作用

在我的控制器方法中:

public ActionResult Index(string sortOrder, string searchString)
{
    var employeesSearch = from s in db.Employees
                       select s;

    if (!String.IsNullOrEmpty(searchString))
    {
            employeesSearch = employeesSearch.Where(s => s.FullName.Contains(searchString)
                                   || s.Site.SiteName.Contains(searchString)
                                   || s.Area.Area1.Contains(searchString)
                                   || s.Discipline.Discipline1.Contains(searchString));
   }

}
我认为:

@using (Html.BeginForm())
{
    <p>
        Find by name: @Html.TextBox("SearchString")
        <input type="submit" value="Search" />
    </p>
}
@使用(Html.BeginForm())
{

按名称查找:@Html.TextBox(“搜索字符串”)

}
@Html.BeginForm()
中指定
操作名
控制器名
表单类型
,如下所示:

@using (Html.BeginForm("Index","YourControllerName", FormMethod.Post))
{
    <p>
        Find by name: @Html.TextBox("SearchString")
        <input type="submit" value="Search" />
    </p>
}

它现在应该对你有用。

定义“不工作”,这对我们毫无帮助。您希望这段代码做什么?请提供输入和输出值。很抱歉,当单击按钮时,它不会进行筛选。您只阅读了我的部分评论,而忽略了其余部分。我希望它根据您在搜索中提供的任何输入来筛选表bar@TanvirArjel是的,我成功了!!再次感谢你!!
public ActionResult Index(string sortOrder, string searchString)
{
    var employeesSearch = from s in db.Employees
                   select s;

    if (!String.IsNullOrEmpty(searchString))
    {
        employeesSearch = employeesSearch.Where(s => s.FullName.Contains(searchString)
                               || s.Site.SiteName.Contains(searchString)
                               || s.Area.Area1.Contains(searchString)
                               || s.Discipline.Discipline1.Contains(searchString));
    }

   return View(employeesSearch.ToList());

}