Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web API customize Help Page

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>
like image 350
xtrip Avatar asked Oct 04 '13 16:10

xtrip


2 Answers

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.

like image 173
Ken Dudley Avatar answered Oct 16 '22 12:10

Ken Dudley


Order in the loop:

<div>                    
   <section>
    @foreach (var group in apiGroups.OrderBy(x => x.Key))
    {
        @Html.DisplayFor(m => group, "ApiGroup")
    }
   </section>
</div>
like image 4
LordHits Avatar answered Oct 16 '22 13:10

LordHits