Search Route in ASP.NET MVC
Posted
by olst
on Stack Overflow
See other posts from Stack Overflow
or by olst
Published on 2010-03-30T22:20:56Z
Indexed on
2010/03/30
22:23 UTC
Read the original article
Hit count: 449
Hi. I have a simple search form in my master page and a serach controller and view. I'm trying to get the following route for the string search term "myterm" (for example): root/search/myterm
The form in the master page :
<% using (Html.BeginForm("SearchResults", "Search", FormMethod.Post, new { id = "search_form" }))
{ %>
<input name="searchTerm" type="text" class="textfield" />
<input name="search" type="submit" value="search" class="button" />
<%} %>
The Controller Action:
public ActionResult SearchResults(string searchTerm){...}
The Route I'm Using :
routes.MapRoute(
"Search",
"search/{term}",
new { controller = "Search", action = "SearchResults", term = (string)null }
);
routes.MapRoute(
"Default",
"{controller}/{action}",
new { controller = "Home", action = "Index" }
);
I'm always getting the url "root/search" without the search term, no matter what search term I enter.
Thanks.
© Stack Overflow or respective owner