在MVC应用程序中,客户端向服务器发送请求时出现错误,希望将消息返回给客户端。尝试使用HttpStatusCodeResult,但只返回没有消息的404错误,我需要将错误的详细信息发送回客户端。
public ActionResult GetPLUAndDeptInfo(string authCode)
{
try
{
//code everything works fine
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return new HttpStatusCodeResult(404, "Error in cloud - GetPLUInfo" + ex.Message);
}
}
ModelState
。- 如果 OP 想显示警告而不是错误,就没有什么可以切换的了。你有什么想法? - Zimano