2014-09-29 63 views
5

最近,我已經開始使用新的web api幫助頁面功能,該功能最近已添加到web api項目模板中。我注意到有些「附加信息」欄總是「無」。Microsoft Web API幫助頁面 - 如何爲參數創建註釋

​​

經過一番尋找標記我發現這個信息應該從屬性

<td class="parameter-annotations"> 
        @if (parameter.Annotations.Count > 0) 
        { 
         foreach (var annotation in parameter.Annotations) 
         { 
          <p>@annotation.Documentation</p> 
         } 
        } 
        else 
        { 
         <p>None.</p> 
        } 
       </td> 

但是,什麼樣的屬性我應該使用的,填充更多的信息到達? 謝謝

回答

8

有關如何添加附加信息的示例,請參見this site

它基本上標註模型,所以在你的情況下,它會是這樣的: -

public class Product 
{ 
    /// <summary> 
    /// The id of the product 
    /// </summary> 
    [Required] 
    public int Id { get; set; } 

    /// <summary> 
    /// The name of the product 
    /// </summary> 
    [MaxLength(50)] 
    public string Name { get; set; } 
} 

這將使你像這樣的輸出: -

example output