返回空的ActionResult [英] Returning Empty ActionResult
本文介绍了返回空的ActionResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可能遇到的情况,当我需要只返回错误的请求的结果。
I may encounter situations, when I need to just return bad request result.
例如,有一个MVC 3网站的控制器行动的号召,但所需的参数是在请求URI失踪。
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?
推荐答案
您的解决方案将工作确定,但更明确的方式将使用的HTTPStatus codeResult
类,像这样的:
Your solution will work OK, but more clear way will be using HttpStatusCodeResult
class, like this:
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
这篇关于返回空的ActionResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文