2014-01-07 28 views
8

我有一個簡單的webapi2項目。在WebApi2幫助頁面中啓用文檔

我似乎可以發現自己指的是舊的webapi1

從我的控制器,如果我有

/// <summary> 
    /// Gets a list of not very interesting information 
    /// </summary> 
    /// <returns>The list</returns> 
    [ResponseType(typeof(ExampleModel))] 
    public IHttpActionResult Get() 
    { 
     var data = new List<ExampleModel>() 
     { 
      new ExampleModel() 
      { 
       Date = DateTime.Now, 
       Name = "Tom" 
      }, 
      new ExampleModel() 
      { 
       Date = DateTime.Now.AddDays(-20), 
       Name = "Bob" 
      } 
     }; 

的唯一信息就是爲什麼出現,當我嘗試瀏覽到幫助頁面的信息。我被告知沒有可用的文件。

是否有一個魔術開關會打開這個數據的自動填充?

+0

可能有[ASP.NET Web API幫助頁面文檔使用控制器上的Xml註釋](http://stackoverflow.com/questions/14843243/asp-net-web-api-help-page-documentation-using-xml-comments-on-controllers) –

回答

10

,如果你指的是顯示XML註釋,那麼你可以在這裏找到我的答案:

ASP.NET Web API Help Page documentation using Xml comments on controllers

一定要在區域去掉這一代碼/ HelpPage/App_Start/HelpPageConfig.cs

// Uncomment the following to use the documentation from XML documentation file. 
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml"))); 

還要確保xml文件進入App_Data而不是bin,它默認在項目屬性中

+0

我曾嘗試過沒有任何運氣,但是根據帖子的日期不確定其是否仍然與webapi2 –

+8

實際上仍然與Web API 2相關。順便說一句,你是否取消註釋'HelpPageConfig.cs'中的代碼行來啓用xml文件中的文檔? –

+0

對不起,你是對的。謝謝。 –