如何在客户端返回错误消息,状态code [英] How to return on client error message with status code
本文介绍了如何在客户端返回错误消息,状态code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用这样的:
return Request.CreateResponse(HttpStatusCode.InternalServerError, "My message");
也是我想这一个:
also I tried this one:
return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "My message");
不过,我看到我的浏览器,虽然在显示,如我的信息的任何消息500错误。
But I see 500 error on my browser though any message like "My message" are displayed.
推荐答案
要与ASP.NET MVC控制器使用的消息返回一个特定的响应code:
To return a specific response code with a message from ASP.NET MVC controller use:
return new HttpStatusCodeResult(errorCode, "Message");
请确保在控制器的方法类型的ActionResult,不是的ViewResult。
Make sure the method in the controller is type ActionResult, not ViewResult.
这篇关于如何在客户端返回错误消息,状态code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文