Microsoft Web API帮助页面 - 如何创建参数注释 [英] Microsoft Web API Help page - how to create annotations for parameters

查看:126
本文介绍了Microsoft Web API帮助页面 - 如何创建参数注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我开始玩新的web api帮助页面功能,最近被添加到web api项目模板。我有一个通知,一些附加信息列总是无。





经过一些查看标记后,我发现这个信息应该从属性到达$ /

 < td class =parameter-annotations> 
@if(parameter.Annotations.Count> 0)
{
foreach(parameter.Annotations中的var annotation)
{
< p> @annotation。文档和LT; / p为H.
}
}
else
{
< p>无。< / p>
}
< / td>

但是,我应该使用什么样的属性来填充其他信息?
谢谢

解决方案

请参阅本网站,了解如何添加附加信息。



它基本上是注释你的模型,所以在你的情况下,它将是这样的: -

  public class Product 
{
///< summary>
///产品的ID
///< / summary>
[必需]
public int Id {get;组; }

///< summary>
///产品名称
///< / summary>
[MaxLength(50)]
public string Name {get;组; }
}

哪个会给你这样的输出: -




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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆