Returning Empty ActionResult

2019-06-14 21:23发布

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?

1条回答
Animai°情兽
2楼-- · 2019-06-14 21:56

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

return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
查看更多
登录 后发表回答