ASP.NET MVC search route

Posted by sahina on Stack Overflow See other posts from Stack Overflow or by sahina
Published on 2010-05-03T14:27:27Z Indexed on 2010/05/03 17:28 UTC
Read the original article Hit count: 194

Filed under:
|

I setup a search route:

routes.MapRoute(
 "Search",
 "Search/{q}",
 new { controller = "Search", action = "Index" }
);

The search form has an input box and a button. I want the search with a GET as below.

<% using(Html.BeginForm("Index", "Search", FormMethod.Get))
{%>
    <%:Html.TextBox("q")%>
        <span class="query-button">
        <input type="submit" value="select" /></span>
    <% } %>
 </div>

The action on the SearchController is:

public ActionResult Index(string q)
{
   // search logic here

   return View(new SearchResult(q));
}

The URL becomes like this: http://localhost:19502/search?q=mvc+is+great

But I want the search to be like: http://localhost:19502/search/mvc+is+great

How do I setup the route or the Html.BeginForm

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about routing