有什么方法可以使用 apiController 的验证方法吗?

Is there any way to use method Validate of apiController?

我想在我的API中使用这个方法,但是它无效。

Error when I've tried to use this.Validate();

来源:https://docs.microsoft.com/en-us/dotnet/api/system.web.http.apicontroller.validate?view=aspnetcore-2.2

如果您将 ApiController class 继承给您的控制器,那么您可以使用 this 运算符

调用它

例如,

using System;
using System.Web.Http;
...
public class SampleController : ApiController
{

   public IActionResult GetSample()
   {
       //Your code goes here
       this.Validate();  //This is the way to call Validate method
   }
}