搜索功能在localhost上正常运行,但未在mvc中的托管服务器上运行

时间:2019-01-17 16:35:42

标签: asp.net model-view-controller

我创建了一个mvc网站,该网站在我的本地主机上运行良好,但是当我在服务器上上传相同的代码时,它向我显示了服务器上的错误:

  

对象引用未设置为对象的实例

我在方法索引中具有搜索功能。此函数在localhost中工作正常,但在此行中出现错误:

hairDressers = hairDressers.Where(m => m.HairDresserName.Contains(searchString));

请帮助我。

    public ViewResult Index(string sortOrder, string currentFilter, string searchString, int? page)
    {
        ViewBag.citySortParm = IsNullOrEmpty(sortOrder) ? "City" : "City_des";
        ViewBag.nameSortParm = sortOrder == "Name" ? "Name_desc" : "Name";
        if (searchString != null)
        {
            page = 1;
        }
        else
        {
            searchString = currentFilter;
        }

        ViewBag.CurrentFilter = searchString;
        var hairDressers = unitOfWork.HairDresserGenericRepository.Get(includeProperties: "City");
        if (searchString!=null)
        {
            hairDressers = hairDressers.Where(m => m.HairDresserName.Contains(searchString));
        }
        switch (sortOrder)
        {
            case "Name":
                hairDressers = hairDressers.OrderBy(s => s.HairDresserName);
                break;
            case "Name_des":
                hairDressers = hairDressers.OrderByDescending(s => s.HairDresserName);
                break;
            case "City":
                hairDressers = hairDressers.OrderBy(s => s.City.Name);
                break;
            case "City_des":
                hairDressers = hairDressers.OrderByDescending(s => s.City.Name);
                break;
            default:
                hairDressers = hairDressers.OrderByDescending(s => s.City.Name);
                break;
        }

        int pageSize = 100;
        int pageNumber = (page ?? 1);
        return View(hairDressers.ToPagedList(pageNumber, pageSize));
    }

0 个答案:

没有答案