【问题标题】:ASP.NET Web API customize Help PageASP.NET Web API 自定义帮助页面
【发布时间】:2014-03-15 05:31:11
【问题描述】:

我注意到,Web API 在帮助页面中没有按任何特定顺序(或至少按 API 名称)排序。如果可能的话,我想按名称类别订购。无法很好地在 ToLookup 上使用 OrderBy。这是它默认附带的代码:

@{

 // 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>

【问题讨论】:

    标签: asp.net-web-api


    【解决方案1】:

    上面的答案几乎是正确的,它只是需要在最后关闭控制器名称。

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

    我测试了它,现在一切正常。

    【讨论】:

      【解决方案2】:

      循环中的顺序:

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

      【讨论】:

        【解决方案3】:
        ILookup<string, ApiDescription> apiGroups = Model.OrderBy(d => d.ActionDescriptor.ControllerDescriptor.ControllerName).ToLookup(api => api.ActionDescriptor.ControllerDescriptor.ControllerName);
        

        【讨论】:

          猜你喜欢
          • 2016-12-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-11-18
          • 1970-01-01
          • 2014-12-27
          • 2015-04-07
          相关资源
          最近更新 更多