生成的WEB API帮助区文档不显示响应正文格式/示例

Cem*_*mre 8 c# documentation asp.net-mvc-areas asp.net-web-api asp.net-web-api2

我已经为我的web api 2项目创建了一个帮助区域文档(基于owin/katana).我打开配置中的所有设置并安装Microsoft.AspNet.WebApi.OData.目前我有以下设置:

config.SetSampleObjects(new Dictionary<Type, object>
{
    {typeof(string), "sample string"},
    {typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
});

config.SetSampleForMediaType(
    new TextSample("Binary JSON content. See http://bsonspec.org for details."),
    new MediaTypeHeaderValue("application/bson"));

config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));

config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");

config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");

config.SetActualRequestType(typeof(string), "Values", "Get");

config.SetActualResponseType(typeof(string), "Values", "Post");
Run Code Online (Sandbox Code Playgroud)

但是,我没有生成任何响应样本.我的网页看起来像我在网上看到的那样

应该是什么样子

但它就像这样松散.如何显示JSON等样本响应格式,如第一张图片所示?

在此输入图像描述

Bru*_*nha 2

这是因为内容谈判。您可能在回复中指定了类似的内容:

config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>))
Run Code Online (Sandbox Code Playgroud)

这会阻止内容协商正常工作,因此帮助页面中不会生成 JSON 格式。

更多信息:http://blogs.msdn.com/b/yao Huang1/archive/2012/10/13/asp-net-web-api-help-page-part-2-providing-custom-samples-on-the -帮助页面.aspx