【问题标题】:Search redirect and display to current page and thereafter direct to another when item is chosen搜索重定向并显示到当前页面,然后在选择项目时直接到另一个页面
【发布时间】:2019-02-25 09:37:30
【问题描述】:

我正在创建一个汽车租赁网站。我会展示所有可用的车辆,并在一辆被租用/预订后将它们从展示中移除。

在我的可用车辆的显示页面上,我希望使用下拉列表进行搜索,但是,我希望执行搜索并将用户返回到此页面,仅包含经过优化的搜索车辆。此后,一旦用户选择了他想要预订的车辆,他就必须被引导到下一页。

我的车辆 ActionResult:

public ActionResult Vehicles()
    {
        var e = db.Vehicles.Where(x => x.availability == true).ToList();
        return View(e);
    }

我的车辆 ActionResult,发布:

[HttpPost]
    public ActionResult Vehicles(string locationUp, string vehicleID)
    {
        Session["V_LOC"] = locationUp;
        Session["V_ID"] = vehicleID;

        return RedirectToAction("Vehicle_Step_1", "Home");
    }

就目前而言,这会将用户引导至预订车辆的第二步,我如何适应搜索以使用户保持在同一页面上并优化搜索,一旦用户选择车辆,然后引导他们到第二步?

我以前没有这样做过,所以我对如何继续进行有点困惑

【问题讨论】:

    标签: c# asp.net-mvc


    【解决方案1】:

    您可以定义一个模型,该模型定义了用户过滤器:

    public class Filter 
    {
        public string MaxPrice { get; set; }
        public string Make { get; set; }
    }
    

    从您的搜索页面,您需要将此过滤器发布到控制器以优化搜索,因此添加另一个用户可以发布到的操作方法:

    [HttpPost] // <-- note that this one is HttpPost
    public ActionResult Vehicles(Filter userFilter)
    {
        // refine the search and send the user back to Vehicles view
        var e = db.Vehicles.Where(x => x.availability == true && 
                                  x.Price <= userFilter.MaxPrice &&
                                  string.Equal(x.Model, userFilter.Make).ToList();
        return View(e);
    }
    

    这是您最简单的选择...替代方法是使用 Ajax 进行搜索并使用 Ajax 和 JavaScript 更新同一页面上的搜索结果(这肯定会更复杂)。

    【讨论】:

      猜你喜欢
      • 2014-02-22
      • 1970-01-01
      • 2020-06-15
      • 2011-06-02
      • 2018-04-27
      • 2015-06-06
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多