【问题标题】:ASP.Net WebApi Help Pages Sample GenerationASP.Net WebApi 帮助页面示例生成
【发布时间】:2015-06-20 03:10:50
【问题描述】:

我正在为 WebApi 使用 ASP.net 帮助页面。在我的一些响应格式示例中,我收到了与格式化程序有关的错误。我查看了各种教程,它们似乎都展示了如何覆盖 form-url-encoded 格式。我没有找到任何可以覆盖其他格式的东西:

应用程序/json、文本/json、文本/html、应用程序/xml、文本/xml

为了设置我使用的特定类型的样本

 config.SetSampleForType("MessageGoesHere", new 
         MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(TypeGoesHere));

这有助于为表单 urlencoded 响应格式设置示例。我尝试用 application/json 或其他示例之一替换 MediaTypeHeader 值,但没有效果。

我的问题:我如何设置响应格式的示例,而不是 ASP.net 帮助页面上的 form-urlencoded?

【问题讨论】:

    标签: c# asp.net-mvc asp.net-web-api


    【解决方案1】:

    我遇到的问题是我没有在 typeof 参数中使用精确的类型。当我应该使用 IQueryable 时,我使用的是通用集合。

    config.SetSampleForType("MessageGoesHere", new 
         MediaTypeHeaderValue("application/json"), typeof(ExactTypeGoesHere));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-08
      • 1970-01-01
      • 2013-06-04
      • 2013-09-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多