Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree with @Tim that you should use a single controller. A controller is a logical grouping of actions; for example the CRUD operations for Foo. <a href="http://nerddinner.codeplex.com/" rel="nofollow">NerdDinner</a> is a good example of this.</p> <p>I disagree with the routes. You can do whatever you want with the routing; but it should be meaningful to the user. You probably just have a single catchall route similar to the one below.</p> <pre><code> routes.MapRoute("Default", //RouteName "{controller}/{action}/{id}", //RouteUrl new { //RouteDefaults controller = "Home", action = "Index", id = UrlParameter.Optional} ) </code></pre> <p>You can have the routes you want by using a single controller.</p> <p>Your desired urls:</p> <blockquote> <p>myapp/Home<br> myapp/Summary/prop1/prop2<br> myapp/Detail/prop1/prop2/prop3</p> </blockquote> <p>The controller setup:</p> <pre><code>public class HomeController : Controller { public ActionResult Index() { ... } public ActionResult Summary() { ... } public ActionResult Details() { ... } } </code></pre> <p>The routing setup:</p> <pre><code> routes.MapRoute("Home-Index", //RouteName "myapp/Home", //RouteUrl new { //RouteDefaults controller = "Home", action = "Index"}); routes.MapRoute("Home-Summary", //RouteName "myapp/Summary/prop1/prop2", //RouteUrl new { //RouteDefaults controller = "Home", action = "Summary", prop1 = UrlParameter.Optional, prop2 = UrlParameter.Optional}); routes.MapRoute("Default", //RouteName "{controller}/{action}/{id}", //RouteUrl new { //RouteDefaults controller = "Home", action = "Index", id = UrlParameter.Optional} ) </code></pre> <p>Now there are a few important things to note:</p> <ol> <li><p>Routing works like a switch statement, the first url that matches is the one it will use, that's why you have the catchall as the last one.</p></li> <li><p>The url defined in your map route can be whatever you want. It doesn't have to match with the controller, because once you remove the placeholders ({controller}, etc) it uses the default for navigation. So the Home-Index route url could be myapp/foo/bar/baz and id would still take you to the Home index action.</p></li> <li><p>The placeholders work automagically. I have not been able to find a good resource explaining how the default route works.</p></li> </ol> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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