Tool to list MVC routes - Visual Studio Express

rwalter picture rwalter · Nov 30, 2012 · Viewed 11.4k times · Source

I am learning .NET MVC and an app I'm building has become rather spaghetti-like. In my code I have many actions in different controllers which naturally all produce various views and partialviews. To make matters worse, I have @Html.Action commands which add another layer of confusion. Some of this is left over from the default scaffolding action.

Is there any tool that produces a list of all the possible routes in my site and the views they return?

I'd also like to find all the unused views and actions without views and generally refactor everything properly. Something like this (please don't comment on this specific example):

Route               Views returned
------------------------------------------
/User/Edit          /User/Edit.cshtml
/Admin/User/Edit    /User/Edit.cshtml
...

Does such a thing exist? Can it be done with a .tt template?

Or perhaps my whole approach is wrong..!

Answer

Mario S picture Mario S · Nov 30, 2012

These maybe can help you on your way:

I haven't tested the Mvc Route Visualizer, but it seems like it could do what you ask.

Edit:

Maybe this works better for you. It won't show you the views returned, though, it will at least display all controllers and actions:

  1. Add the MvcCodeRouting nuget package to your project.
  2. Go to the method where you register the routes.
  3. After routes.IgnoreRoute("{resource}.axd/{*pathInfo}");, add these lines of code:

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
    // If you don't have "HomeController", choose another controller you have.
    // MvcCodeRouting will look for all controllers in the same namespace and sub-namespaces as the one specified here.
    routes.MapCodeRoutes(typeof(HomeController), new CodeRoutingSettings
    {
        UseImplicitIdToken = true
    });
    
    // Other, existing, routes here...
    
  4. Build and run the application.

  5. Go to http://yoururl.com/routes.axd to see all created routes, they will contain all actions.
  6. If you have installed Route Debugger, you can see them there to:

    Route Debugger screenshot