Closed khellang closed 7 years ago
Thanks for the suggestion, we'll review the request in our next bug triage meeting.
Seems reasonable. We need to add it to both MVC's ControllerBase
and to Razor Pages' PageModelBase
.
I can do the work if you want 😊
go for it! 👍
Should include ControllerBase
, PageModelBase
and PageBase
https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.RazorPages/PageBase.cs
Hmm... I can't seem to find PageModelBase
. Did you mean PageModel
?
Also, there's no existing BadRequest
methods on PageBase
(or PageModel
), so it seems it's already missing quite a few other, similar methods. Should I still go ahead and add UnprocessableEntity
anyway? I think it would make sense to have a common base class for pages and controllers here.
@rynowak PageBase \ PageModel we intentionally skipped a bunch of API focused IActionResult methods from Razor Pages (See https://github.com/aspnet/Mvc/issues/5846). Presumably this is one the methods that isn't required here either.
@DamianEdwards / @rynowak - thoughts on adding various other missing result factory methods? Were we trying to avoid more API-ish things appearing in Razor Pages or anything like that? Or do we want parity?
Yeah, let's leave it out for now. No one has asked for it
Should the BadRequest
method which takes a ModelStateDictionary
as parameter be deprecated in favor of the new UnprocessableEntity
method?
public virtual BadRequestObjectResult BadRequest(ModelStateDictionary modelState);
Perhaps the method should be marked with the Obsolete attribute?
Note that the ValidationProblem
method introduced in ASP.NET Core 2.1 have a overload that takes a ModelStateDictionary
as parameter and returns a 400 status code.
It's not obsolete, it's just that there's no consensus on using 400 for validation errors. Some people use 400 for all client errors, like syntax and validation, while some prefer 400 for syntax error and 422 for semantic validation errors. MVC will still default to 400.
422 Unprocessable Entity
is commonly used for semantic validation errors in APIs, as opposed to400 Bad Request
for syntactical errors:It would be nice if MVC included an
UnprocessableEntityResult
and an accompanyingControllerBase.UnprocessableEntity
method.They'd basically mirror what
BadRequestResult
andControllerBase.BadRequest
does, only with a different status code.This has been requested before by @ashmind, but was never followed up.