在MVC中实施FileResult时如何解决错误“找不到文件”?

时间:2019-05-16 13:05:08

标签: c# asp.net-mvc asp.net-mvc-5 fileresult

我有锚标记,并在“ href”中提供了操作。单击标签时,如果未找到文件路径,则显示错误“找不到文件”。 我想要类似未找到文件路径的结果,则不想显示错误。 以下是我的代码:

"<a href="/projectmou/Download/1">Download </a>"

  public ActionResult Download(string id)
        { 
           try
              {

                if (System.IO.File.Exists(path))
                {
                    return File(path, contentType, "file.pdf");
                }
                else
                {
                    return null;
                }

            }
            catch (Exception ex)
            {
                return null;
            }
        }

我想要这样的结果:如果找不到文件路径,则不想显示错误。

0 个答案:

没有答案
相关问题