Order the controllers in ASP.NET WebAPI Help

Recently I started a new API project for my company.  With this project I decided to give the Help files generator that Microsoft created a try.  Overall it looks like it will meet the needs of the project.  Today however I hit my first snag with it.  After I began to turn on routes for consumption I noticed in the help page that the routes was not sorted in any fashion.  To me, this can cause a level of annoyance for the folks needing to consume this. 

To solve this it was fairly trivial

  • Go to \Areas\HelpPage\Views\Help\
  • Open Index.cshtml
  • Locate the following line

ILookup<HttpControllerDescriptor, ApiDescription> apiGroups = Model

.ToLookup(api => api.ActionDescriptor.ControllerDescriptor);

  • Replace that line with this one

ILookup<HttpControllerDescriptor, ApiDescription> apiGroups = Model

.OrderBy(d => d.ActionDescriptor.ControllerDescriptor.ControllerName)

.ToLookup(api => api.ActionDescriptor.ControllerDescriptor);

What we are doing here is first sorting the model before the lookup can be created.

This entry was posted in ASP.NET, C# and tagged . Bookmark the permalink.

4 Responses to Order the controllers in ASP.NET WebAPI Help

  1. mm says:

    wonderful find …. this was bugging me

  2. Jared Ricks says:

    Thank you. I appreciate this information. It gets to be a pain when you have a lot of controllers!

  3. James Beam says:

    Great Post !

Comments are closed.