API 文档中的自定义附加信息

custom additional information in API documentation

我已阅读 here 网络 API 帮助页面的其他信息。数据注释实际上为文档提供了附加信息。但是我想知道有没有没有数据注释的额外信息?

如果是那么怎么办?

如果没有,那么是否可以用数据注释覆盖附加信息,例如

[Required]

shows Required written in additional information 但是如果我想显示 "This field is required" 或类似的东西怎么办?

谢谢

编辑 看图片我想尽可能更新没有数据注释的附加信息。

因此注释允许您进一步指定要求,即如果您有以下模型:

public class MyModel {

    [Required(ErrorMessage = "You seriously need a name here bro")]
    public string Name{ get; set; }

}

然后您可以自动在 ASP.Net 页面中显示验证消息,如下所示:

@model string
@Html.TextBoxFor(m => m)
@Html.ValidationMessageFor(model => model, "", new { @class = "text-danger"})

所以基本上,您为验证消息添加一个字段,当 Required 属性启动时,该字段将由 ASP.Net 填充。

您可以编辑 Required AttributeModelDescriptionGenerator.cs
Areas>HelpPage>ModelDescriptions>ModelDescriptionGenerator.cs
例如:

    [Required(ErrorMessage ="Must pass")]
    public string Name { get; set; }

我得到: 附加信息:必须通过

替换:

 { typeof(RequiredAttribute), a => "Required" }

与:

{ typeof(RequiredAttribute), a => {
            RequiredAttribute b =(RequiredAttribute)a;
            return (b.ErrorMessage);
        }

see

如果您想提供自定义附加信息(使用数据注释),那么@Pedro G. Dias 的答案就是您的解决方案,但如果您想在不使用数据注释的情况下提供附加信息,恐怕这是不可能的,或者正如@DynamicVariable 对你的问题所评论的那样,你必须使用一些替代程序来做到这一点。

PS。我已经调试文档项目进行检查,发现附加信息实际上是由数据注释提供的。