I have a search box on my page (.cshtml) with 3 drop down boxes (Country, State, City). When I click on Search button, the URL needs to be changed to like below.
http://localhost:1234/OrderHistory/Orders (default)
When I click on search with values in dropdowns, the url is to be changed to
http://localhost:1234/OrderHistory/Orders/dropbox1val/dropbox2val/dropbox3val
How to rewriting in asp.net mvc 4?
You need to refine your URL Scheme in the RegisterRoutes(RouteCollection routes)
method. I think somethink like the following might give you a clue. routes.MapRoute("RouteName", "Dropdown1{variableNameHoldingTheValue}/Dropdown2{variableNameHoldingTheValue}/DropDown3{variableNameHoldingTheValue}", new { controller = "ControllerName", action = "ActionName" }, // You might add consrtaints here );
EDIT:
if you want this URL to be your default
http://localhost:1234/OrderHistory/Orders (default)
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "OrderHistory", action = "Orders", id = UrlParameter.Optional } );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.