I have a simple search form on my main page and a controller and view. I am trying to get the following route for the search string "myterm" (for example): root / search / myterm
Form on the main 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" /> <%} %>
Controller action:
public ActionResult SearchResults(string searchTerm){...}
The route I am 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 always get the root / search URL without a search query, no matter what search query I enter.
Thanks.
vobs
source share