Question

I have scoured the web for a decent explanation of the routing syntax in ASP.NET MVC Beta 1 but I still can't get it to work.

Please could someone explain what I need to put in my Global.asax.cs file to have two supported URIs for my site:

www.mysite.com/map.aspx (i.e the site without any explicit parameters/actions for performing the default action), and,

www.mysite.com/map.aspx/search/searchParam1/searchParam2/searchParam3/ (for performing a search)

PS: In the meantime, I'll continue working on this and I'll post the answer myself if I find it.

Was it helpful?

Solution

routes.MapRoute("Default", "map.aspx", new { controller = "DefaultController", action = "DefaultAction" });

routes.MapRoute("Search", "map.aspx/search/{*params}", new { controller = "SearchController", action = "Search" } );

Example URL : http://www.mysite.com/map.aspx/search/dogs/cats/

Parameters passed to SearchController.Search() : params="/dogs/cats"

You can then parse the params in order to process your search results.

However, in my opinion, putting map.aspx in the URL looks wrong if you are building an MVC application. Your url should look like http://www.mysite.com/search/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top