I noticed in ASP.NET Core MVC ModelStateInvalidFilter
checks if Context.Result == null
before checking ModelState.IsValid
? What's the reason?
CodePudding user response:
The answer in the Result
property description comment in the ActionExecutingContext.cs:
Gets or sets the
IActionResult
to execute. SettingResult
to a non-null value inside an action filter will short-circuit the action and any remaining action filters.
This means if the short-circuit of the action already initiated there is no reason to overwrite the previous value in case the context.ModelState.IsValid
set to false
. It would be wrong approach.