Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC Routing with Default Controller
    primarykey
    data
    text
    <p>For a scenario, I have a ASP.NET MVC application with URLs that look like the following:</p> <pre><code>http://example.com/Customer/List http://example.com/Customer/List/Page/2 http://example.com/Customer/List http://example.com/Customer/View/8372 http://example.com/Customer/Search/foo/Page/5 </code></pre> <p>These URLs are achieved with following routes in <code>Global.asax.cs</code></p> <pre><code>routes.MapRoute( "CustomerSearch" , "Customer/Search/{query}/Page/{page}" , new { controller = "Customer", action = "Search" } ); routes.MapRoute( "CustomerGeneric" , "Customer/{action}/{id}/Page/{page}" , new { controller = "Customer" } ); //-- Default Route routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Customer", action = "Index", id = "" } ); </code></pre> <p>These all have gone well until a new requirement arrived and wants to drop keyword 'Customer' off the URL, to make the URLs look like:</p> <pre><code>http://example.com/List http://example.com/List/Page/2 http://example.com/List http://example.com/View/8372 http://example.com/Search/foo/Page/5 </code></pre> <p><strong><em>Edit:</strong> corrected example links, thanks to @haacked.</em></p> <p>I tried to add new <code>MapRoutes</code> to take <code>{action}</code> only and have default controller set to Customer. eg/</p> <pre><code>routes.MapRoute( "CustomerFoo" , "{action}" , new { controller = "Customer", action = "Index" } ); </code></pre> <p>This seems to work, however now all links generated by Html.ActionLink() are weird and no longer URL friendly.</p> <p>So, is this achievable? Am I approaching in the right direction?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload