5

I have noticed, the web API's do not get ordered in any specific order (or at least by API name) in the help page. I would like to order by name category if possible. Unable to use OrderBy on ToLookup very well. Here is the code it comes with by default:

@{

 // Group APIs by controller
  ILookup<string, ApiDescription> apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor.ControllerName);
 }


<div>                    
   <section>
    @foreach (var group in apiGroups)
    {
        @Html.DisplayFor(m => group, "ApiGroup")
    }
   </section>
</div>

3 Answers 3

9

The above answer is almost right it just needed the controllername off on the end.

ILookup<HttpControllerDescriptor, ApiDescription> apiGroups = Model.OrderBy(d => d.ActionDescriptor.ControllerDescriptor.ControllerName).ToLookup(api => api.ActionDescriptor.ControllerDescriptor);

I tested it and all works now.

Sign up to request clarification or add additional context in comments.

Comments

4

Order in the loop:

<div>                    
   <section>
    @foreach (var group in apiGroups.OrderBy(x => x.Key))
    {
        @Html.DisplayFor(m => group, "ApiGroup")
    }
   </section>
</div>

Comments

0
ILookup<string, ApiDescription> apiGroups = Model.OrderBy(d => d.ActionDescriptor.ControllerDescriptor.ControllerName).ToLookup(api => api.ActionDescriptor.ControllerDescriptor.ControllerName);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.