2013-03-28 127 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

相关问题