From Asp.Net Core 2.1 there is a built-in parameter [BindRequired] which is doing this validation automatically.
public async Task<ActionResult<string>> CleanStatusesAsync([BindRequired,
FromQuery]string collection, [BindRequired, FromQuery]string repository,
[BindRequired, FromQuery]int pullRequestId)
{
// all parameters are bound and valid
}
If you are calling this method without parameters, a ModelState error is returned:
{
"collection": [
"A value for the 'collection' parameter or property was not provided."
],
"repository": [
"A value for the 'repository' parameter or property was not provided."
],
"pullRequestId": [
"A value for the 'pullRequestId' parameter or property was not provided."
],
}
More details you can find in this excellent article.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…