2013-03-28 53 views
8

我有一個接收來自Person類型的FromBody參數的發佈操作。在HelpPage中,我得到關於Person參數的信息。是否可以在Person中列出有關屬性的信息,並使用XML文檔文件中的文檔來獲取每個屬性的描述?ASP.Net Web API幫助頁面:文檔複雜類型屬性

public class PersonController : ApiController 
{ 
    /// <summary> 
    /// Add a person 
    /// </summary> 
    /// <param name="person">Person to add</param> 
    /// <returns></returns> 
    [HttpPost] 
    public HttpResponseMessage Add([FromBody] Person person) 
    { 
     // ... 

     return Request.CreateResponse(HttpStatusCode.Created); 
    } 
} 

/// <summary> 
/// A person 
/// </summary> 
public class Person 
{ 
    /// <summary> 
    /// The name of the person 
    /// </summary> 
    public String Name { get; set; } 

    /// <summary> 
    /// The age of the person 
    /// </summary> 
    public Int32 Age { get; set; } 
} 
+0

目前這不支持開箱即用。有一個相關工作項目要求爲模型上使用的數據註釋屬性提供幫助頁面生成。您的方案應該在修復後修復:http://aspnetwebstack.codeplex.com/workitem/877 –

+0

謝謝!在這裏作出答覆,我會將其標記爲答案! –

+0

你有沒有用'///'評論來處理這個問題?通過@KiranChalla鏈接到的工作項目似乎已經實現了註釋支持,但截至2015年10月,文檔仍然沒有顯示在幫助頁面上。 – Mendhak

回答

6

目前這不支持開箱即用。有一個相關工作項目要求爲模型上使用的數據註釋屬性提供幫助頁面生成。您的方案應該在修復後適用:http://aspnetwebstack.codeplex.com/workitem/877

+0

最新版本(我正在使用ASP.NET Web API 2.2以及MVC5)現在包括生成的幫助文件,它們顯示所使用的數據註釋。有關詳細信息,請參閱http://www.strathweb.com/2014/01/return-types-action-parameters-and-data-annotations-now-available-in-web-api-2-1-help-page/。 – DigitalDan

相關問題