3

I am writing a web service using Microsoft Web API Controller classes (v2.1) and using XML at the beginning of each class and method to automatically generate the documentation. The generated documentation has a home page listing each class and method with a link to see more details.

Unfortunately, this home (or index) page shows the classes in what appears to me to be a random order, making it hard to find the classes you want.

Is there a way to get them to appear in alphabetical order?

Jim S
  • 1,069
  • 3
  • 10
  • 17

1 Answers1

1

In folder Areas\HelpPage\Views\Help is a file named index.cshtml which is the template for generating the help documentation. It contains the following code that generates the home page:

<section class="content-wrapper main-content clear-fix">
    @foreach (var group in apiGroups) {
        @Html.DisplayFor(m => group, "ApiGroup")
    }
</section>

The classes can be placed in alphabetical order by inserting one line before the @foreach and making one change in the @foreach line, as follows:

<section class="content-wrapper main-content clear-fix">
    @{var orderedGroups = (from g in apiGroups orderby g.Key.ControllerName select g).ToArray();}
    @foreach (var group in orderedGroups) {
        @Html.DisplayFor(m => group, "ApiGroup")
    }
</section>

The new line simply sorts the classes before generating the home page.

Jim S
  • 1,069
  • 3
  • 10
  • 17
  • Why did you answer your own question so fast? Did you ask this question just to get a medal? – thinklarge Jul 11 '15 at 17:29
  • I checked the StackOverflow help to find how to post information when there is not a question, and I learned from http://stackoverflow.com/help/self-answer that the approved way is to post a question and answer it yourself. When you post a question, there is even a checkbox you can click to indicate you want to answer your own question. – Jim S Jul 11 '15 at 20:47
  • Ok cool didn't know that. Just curious I haven't seen it a lot. – thinklarge Jul 11 '15 at 22:00