I have a form like below:-
<% using ( Html.BeginForm("search", "home", FormMethod.Get) ) { %>
<%= Html.TextBox("location", "") %>
<input type="submit" value="Search All Jobs" />
<% } %>
and in global.asax i have this route
routes.MapRoute(
"Search", // Route name
"{controller}/{action}/{location}", // URL with parameters
new { controller = "Home", action = "Index", location = UrlParameter.Optional } );
now whenever i click on submit button i get the url like
http://localhost/home/search?location=karachi
but i want
http://localhost/home/search/karachi
Any idea?
The url you are getting is normal, that’s how according to the specification GET parameters are sent by browsers and there’s not much you could do about it.
Your best bet is javascript to intercept the submission of the form, canceling the default action and rewriting the url. Personally I wouldn’t bother with this and leave the browsers send user input as defined in the specification.
But if you really insist on achieving this here’s an example of javascript: