Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find BadRequest method

Tags:

asp.net-core

I read this announcement

https://github.com/aspnet/Announcements/issues/153

HttpBadRequest is now BadRequest

but I can't find a BadRequest method and what happened to this.Ok(Object) method?

like image 938
user3369579 Avatar asked Apr 23 '26 19:04

user3369579


1 Answers

Regarding Bad Requests

As mentioned in this related GitHub issue comment, you would actually create a new instance of a BadRequestResult() object :

public IActionResult Index()
{
     return new BadRequestResult();
}

Regarding Ok() Requests

As far as the Ok()method goes, it actually comes from the controller itself, so it should still work as you might expect :

public IActionResult Index()
{
     return this.Ok(yourObject);
}

However, there is also an OkResult() and OkObjectResult(), which can return an OK request and one that accepts an object overload as well :

public IActionResult Index()
{
     return new OkResult();
}

public IActionResult Index()
{
     return new OkObjectResult(yourObject);
}
like image 109
Rion Williams Avatar answered Apr 26 '26 09:04

Rion Williams