Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning Empty ActionResult

I may encounter situations, when I need to just return bad request result.

For example, there is a call to MVC 3 site's controllers action, but the required parameter is missing in a request uri.

What do I return in response. I know I can do this:

Response.StatusCode = (int)HttpStatusCode.BadRequest; return Content(string.Empty); 

Is this the correct way for the above described situation?

like image 773
Maxim V. Pavlov Avatar asked Feb 08 '12 15:02

Maxim V. Pavlov


1 Answers

Your solution will work OK, but more clear way will be using HttpStatusCodeResult class, like this:

return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 
like image 155
Sergey Kudriavtsev Avatar answered Sep 21 '22 17:09

Sergey Kudriavtsev