【发布时间】:2013-10-08 06:47:57
【问题描述】:
我正在使用
<img src="@Url.Action("getImage", "AccessFile", new { imagePath= @ViewData["imagePath"] })"/>
在视图中显示作为本地文件存在于服务器中的图像。
AccessFileController 中的 getImage 操作看起来像
public ActionResult getImage(string imagePath)
{
if (!System.IO.File.Exists(imagePath))
{
//Log
return ?????????
}
else
{
return base.File(imagePath, "image/jpg");
}
}
我的问题是,我应该输入什么?????????允许用户看到某种错误信息?
我试过了
- return new HttpNotFoundResult();
- return RedirectToAction("ExpectedError", "Error");
但它只返回带有损坏图标的空图像。
有什么好的解决办法吗?
【问题讨论】:
-
这不是文件结果,actionresult 的解决方案对 actionresult 不起作用
标签: asp.net-mvc exception-handling error-handling actionresult