Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool to list MVC routes - Visual Studio Express [closed]

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..!

like image 424
rwalter Avatar asked Nov 30 '12 13:11

rwalter


People also ask

What is @model in Cshtml?

The @model directive allows access to the list of movies that the controller passed to the view by using a Model object that's strongly typed. For example, in the Index.cshtml view, the code loops through the movies with a foreach statement over the strongly typed Model object: CSHTML Copy.

Which method is used for adding routes to an MVC application?

When an MVC application first starts, the Application_Start() method is called. This method, in turn, calls the RegisterRoutes() method. The RegisterRoutes() method creates the route table. The default route table contains a single route (named Default).

Where is route table stored in MVC?

Where is RouteTable stored in MVC? RouteTable is a collection of routes that is stored in RouteConfig. cs file in App_Start folder of the application.

Where are routes defined in MVC?

Routing in ASP.NET MVC cs file in App_Start Folder, You can define Routes in that file, By default route is: Home controller - Index Method. routes. MapRoute has attributes like name, url and defaults like controller name, action and id (optional).


1 Answers

These maybe can help you on your way:

  • Mvc Route Visualizer (Visual Studio Extension)
  • Route Debugger (Also comes as a nuget package)
  • Glimpse

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

like image 97
Mario S Avatar answered Sep 20 '22 04:09

Mario S