Dar*_*Guy 0 asp.net-mvc-4 asp.net-web-api
我正在使用MVC4项目中的WebApi帮助页面.
根据以下链接,http://blogs.msdn.com/b/yaohuang1/archive/2012/10/13/asp-net-web-api-help-page-part-2-providing-custom-samples- on-the-help-page.aspx我一直在设置HelpPageConfig来设置实际的响应类型.
我有一个控制器,它有两个get方法
/// <summary>
/// Get the list of plans for a specified portfolio
/// </summary>
/// <param name="portfolioIdentifier">Portfolio Identifier (guid)</param>
/// <returns>
/// Returns a list of <see cref="RestDTOs.Plan"/> Plan objects
/// </returns>
public HttpResponseMessage Get(Guid portfolioIdentifier)
{
}
/// <summary>
/// Get full plan details.
/// </summary>
/// <param name="planIdentifier">Plan Identifier (guid)</param>
/// <returns>
/// Returns the <see cref="RestDTOs.Plan"/> Plan object
/// </returns>
[HttpGet]
public HttpResponseMessage Detail(Guid planIdentifier)
{
}
Run Code Online (Sandbox Code Playgroud)
在HelpPageConfig.cs中,我添加了以下内容以尝试设置ResponseBody格式示例
config.SetActualResponseType(typeof(Plan), "Plan", "GET");
Run Code Online (Sandbox Code Playgroud)
这在Get方法上工作得很好,但是在Detail方法上没有产生任何东西
我需要添加到HelpPageConfig中,以便web api帮助将为Detail方法提取并生成样本
MVC 5具有内置属性来设置响应类型.
更多信息请访问:http: //thesoftwaredudeblog.wordpress.com/2014/01/05/webapi-2-helppage-using-responsetype-attribute-instead-of-setactualresponsetype/
只需使用:
ResponseType(typeof([Your_Class]))]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1401 次 |
| 最近记录: |