MVC5:一起过滤结果和分页时遇到问题

MVC5: Having Trouble with Filtering Results And Pagination Together

我有一个添加了分页的索引视图(列表),它运行良好。我还有其他视图(列表),它们有一个 html 搜索框,可以将值传递回控制器并且也可以完美运行。但是,当我尝试将两者放在同一个视图中时。 .我收到空引用错误。

错误信息 值不能为空。 参数名称:值

这是产生错误的行:

var catalogs = supplies.Where(s => s.ItemDescription.Contains(searchString));

这是索引视图上的asp/html搜索框

form asp-controller="Movies" asp-action="Index">
<p>
    Search Catalog Files: <input type="text" name="SearchString">
    <input type="submit" value="Filter" />
</p>

这是我的索引控制器,它有分页和搜索字符串

 public ActionResult Index(string searchString)
    {



         var supplies = db.ICS_Supplies.OrderByDescending(g => g.Supplies_ID).ToList();
        var catalogs = supplies.Where(s => s.ItemDescription.Contains(searchString));
        var model = new PagedList<ICS_Supplies>(catalogs, 1, 10);

        if (!String.IsNullOrEmpty(searchString))
         {

            catalogs = catalogs.Where(s => s.ItemDescription.Contains(searchString));
         }
        return View(model);

    }

这与异步有什么关系吗?我需要使用以下内容吗?

public async Task<ActionResult> Index(string searchString)

或者我是不是顺序错了?该页面工作正常,如果 SearchString 文本框中有文本。 .但是当页面第一次尝试加载时,它失败了。

有什么指点吗?

执行前可以检查searchString是否为null

var catalogs = supplies.Where(s => s.ItemDescription.Contains(searchString ?? string.Empty));