I want clean urls and defined two routes:
routes.MapRoute(
"Search",
"Search",
new { controller = "Search", action = "SearchPanel" }
);
routes.MapRoute(
"SearchResults",
"Search/{content}",
new { controller = "Search", action = "Search", content = string.Empty, query = string.Empty, index = 0 }
);
then I have two actions:
[HttpPost]
public ActionResult Search(string content, string query)
{
if (string.IsNullOrEmpty(query))
{
return RedirectToAction("Home", "Application");
}
return RedirectToAction("Search", new { content = content, query = query }); ;
}
public ActionResult Search(string content, string query, int? index)
{
if (string.IsNullOrEmpty(query))
{
return RedirectToAction("Home", "Application");
}
switch (content)
{
case "products":
return View("ResultsProducts");
case "categories":
return View("ResultsCategories");
default:
return View("ResultsAll");
}
}
I have a common search bar on my main page with a text box and a submit button. He goes to /Search. The name of the text field query. Everything is excellent and excellent. When I click Search, my first action is executed but not executed when called RedirectToAction():
No route in the route table matches the specified values.
I can not find the reason why it does not work.
source
share