有没有一种方法可以在方法输入参数上添加数据注释?

时间:2019-03-18 14:16:50

标签: c# validation .net-core data-annotations

我有以下代码:

 public void Foo(
                 [Required(ErrorMessage = "Null not allowed")]
                 [ModelValidation] //custom validation
                 UserModel user
                 )
    {
          //Do some code
    }

有没有一种方法,调用此方法可以根据数据注释验证输入?

1 个答案:

答案 0 :(得分:0)

要向最终用户显示文档,您可以使用<param>注释作为输入参数,如下所示-

    /// <summary>
    /// This method validates and submits your report for processing 
    /// </summary>    
    /// <param name="ReportName">This is the name of your report</param>
    /// <param name="ReportTotalUSD">This is the total amount in USD</param>
    /// <param name="ReportDate">This is the date you incurred expenses</param>

    [AllowAnonymous]
    [HttpPost]
    [ResponseType(typeof(List<int>))]
    public IHttpActionResult SubmitReport(string ReportName, decimal ReportTotalUSD, DateTime ReportDate)
相关问题