点击时没有网址参数

时间:2018-06-22 09:46:06

标签: c# asp.net-mvc entity-framework-6 url-parameters

我正在尝试遵循本教程,但将其重新用于我自己的应用程序。

https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application

但是,按教程中的说明单击标题时,我遇到了一些问题,我的网址未更改为..

localhost:8000 / Application?sortOrder = Date_desc

相反,我只得到以下内容

localhost:8000 /应用程序

结果sortOrder始终为null,并且排序落入开关中的默认项。

为什么会这样?据我所知,我已按照该教程进行操作。谁能解释我可能在哪里出问题了?

控制器

selected(brokerName: string) {
  console.log(brokerName);
}

查看

public ActionResult Index(string sortOrder, string currentFilter, string searchString, int? page)
    {
        ViewBag.CurrentSort = sortOrder;
        ViewBag.NameSortParam = String.IsNullOrEmpty(sortOrder) ? "Name_desc" : "";
        ViewBag.AppSSortParm = sortOrder == "AppS" ? "AppS_desc" : "AppS";

        if (searchString != null)
        {
            page = 1;
        }
        else
        {
            searchString = currentFilter;
        }

        ViewBag.CurrentFilter = searchString;

        var applications = from a in db.applications select a;

        if (!String.IsNullOrEmpty(searchString))
            applications = applications.Where(s => s.applicationDescription.ToUpper().Contains(searchString.ToUpper()));

        switch (sortOrder)
        {
            case "Name_desc":
                applications = applications.OrderByDescending(s => s.applicationDescription);
                break;
            case "AppS_desc":
                applications = applications.OrderByDescending(s => s.applicationWindowSecurity);
                break;
            case "AppS":
                applications = applications.OrderBy(s => s.applicationWindowSecurity);
                break;
            default:
                applications = applications.OrderBy(s => s.applicationDescription);
                break;
        }

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

1 个答案:

答案 0 :(得分:0)

您需要将actionLink中的参数与控制器Action方法中所期望的相匹配。请注意,ViewBag是动态对象,可以很容易地犯这种错误(因为它在运行时而不是编译时检查成员)。