I want clean URLs and have 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":
// get products
return View("ResultsProducts");
case "categories":
// get categories
return View("ResultsCategories");
default:
// get all
return View("ResultsAll");
}
}
I have a generic search panel in my master page that has a textbox and a submit button. It posts to /Search
. Textbox's name is query
. All fine and great. When I hit Search
my first action gets executed, but fails on RedirectToAction()
call:
No route in the route table matches the supplied values.
I can't seem to find the reason why it doesn't work.