如何在两个控制器之间传递数据
本文关键字:之间 控制器 数据 两个 | 更新日期: 2023-09-27 18:15:06
位于搜索控制器
public ActionResult Index(string what, string where, int page = 1, string cn = "", string sv = "", string ch = "", string deals = "", int brand = 0)
这是第二个名为Quotation的控制器我想传递上述控制器的参数值但我将它们硬编码为搜索水暖工那么我如何将它们从搜索控制器动态地传递到Quotation控制器
public ActionResult Index()
{
WhereInfo interLoc = new WhereInfo();
// SearchService.ResultSet resultSet = (neSearchService.Search()).getSearchResults("plumbers", interLoc, 1.ToString(), User.Identity.Name, "iyp", "", "", "", "", "", "plumbers", 0);
// ViewBag.Search = resultSet;
// return View();
}
重定向到另一个控制器?
return RedirectToAction("Index", "Quotation", new { what = whatParam, where = whereParam, page = pageParam, cn = cnParam, sv = svParam, ch = chParam, deals = dealsParam, brand = brandParam });
或者,将数据放入TempData[]中,但是此存储仅在请求期间有效。
尝试使用TempData
public ActionResult Index(string what, string where, int page = 1, string cn = "", string sv = "", string ch = "", string deals = "", int brand = 0)
{
TempData["details"] = your_variable_with_details;
return RedirectToAction("OtherAction");
}
在你的QuotationController中,测试TempData["details"]
是否为null。
public ActionResult Index()
{
if(TempData["details"]!=null){
// do something here
}
}
TempData用于传递简单数据而不向客户端公开数据