相关文章推荐
一直单身的弓箭  ·  pair Structure | ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm going to return a bad request result in my action filter.

I have two choices:

context.result = new BadRequestResult();

context.result = new BadRequestObjectResult();

It seems there are couple types for all status codes: NotFoundResult - NotFoundObjectResult and so on.

which one I should use and what is differences of these couple types?

Both are for similar purpose, but the second one ( BadRequestObjectResult ) with the difference, an object or a ModelStateDictionary can be passed as a constructor argument, containing the details regarding the error.

Take a look at the constructors in below link.

https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.badrequestobjectresult?view=aspnetcore-3.1

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .