搜索重定向并显示到当前页面,然后在选择项目时指向另一个页面

问题描述 投票:0回答:1

我正在创建一个车辆招聘网站。我显示所有可用的车辆,并在雇用/预订后将其从显示屏中移除。

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

我的车辆行动结果:

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

我的车辆ActionResult,Post:

[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个回答
0
投票

您可以定义一个定义用户过滤器的模型:

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在同一页面上更新搜索结果(肯定会更复杂)。

© www.soinside.com 2019 - 2024. All rights reserved.