Returning Empty ActionResult

与世无争的帅哥 提交于 2019-12-30 16:18:07

问题


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:


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

return new HttpStatusCodeResult(HttpStatusCode.BadRequest);


来源:https://stackoverflow.com/questions/9196773/returning-empty-actionresult

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!