Microsoft Web API 帮助页面 - 如何为参数创建注释 [英] Microsoft Web API Help page - how to create annotations for parameters
问题描述
最近我开始使用新的 web api 帮助页面功能,该功能最近添加到 web api 项目模板中.我注意到某些附加信息"列始终为无".
Recently i've start playing with new web api help page functionality, that was recently added to web api project template. And i have a notice that some "Additional information" column is always 'none'.
在看了一些标记后,我发现这个信息应该来自属性
After some looking at markup i found that this info should arrive from attributes
<td class="parameter-annotations">
@if (parameter.Annotations.Count > 0)
{
foreach (var annotation in parameter.Annotations)
{
<p>@annotation.Documentation</p>
}
}
else
{
<p>None.</p>
}
</td>
但是我应该使用什么样的属性来填充附加信息?谢谢
But what kind of attribute i should use, to populate additional information? Thanks
推荐答案
参见 本网站 了解如何添加附加信息的示例.
See this site for an example of how to add additional information.
它基本上是在注释你的模型,所以在你的情况下它会是这样的:-
It's basically annotating your model, so in your case it would be something like:-
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; }
}
这会给你这样的输出:-
Which would give you an output like this:-
这篇关于Microsoft Web API 帮助页面 - 如何为参数创建注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!