c# - 搜索重定向并显示到当前页面,然后在选择项目时直接到另一个页面
问题描述
我正在创建一个汽车租赁网站。我会展示所有可用的车辆,并在一辆被租用/预订后将它们从展示中移除。
在我的可用车辆的显示页面上,我希望使用下拉列表来搜索类别,但是,我希望执行搜索并将用户返回到此页面,仅包含经过优化的搜索车辆。此后,一旦用户选择了他想要预订的车辆,他就必须被引导到下一页。
我的车辆 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");
}
就目前而言,这将用户引导至预订车辆的第二步,我如何适应搜索以使用户保持在同一页面上并优化搜索,一旦用户选择车辆,然后将他们引导至第二步步?
我以前没有这样做过,所以我对如何继续进行有点困惑
解决方案
您可以定义一个模型,该模型定义了用户过滤器:
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 更新同一页面上的搜索结果(这肯定会更复杂)。
推荐阅读
- rest - 如果我使用 POST 进行幂等操作,我会有什么风险?
- reactjs - react.js 无法通过参数读取图片
- ios - 底部安全区域颜色通过半透明键盘 iOS
- c++ - 具有 int*& 类型的形参的函数如何在调用时将 int 和 int* 作为参数?
- react-native - 如何在羽毛笔工具栏中添加自定义图标
- python - Plotly 图正在父容器之外
- java - 由于伪元素,我无法找到按钮
- javascript - 分阶段设置状态反应
- javascript - 如何从 api 解构数组对象并放入状态?
- python - 如何在python中将count()与文本文件一起使用