繁体   English   中英

静态mvc Web应用程序中服务器中pdf文件的链接

[英]Links for pdf files in server from static mvc web application

我的静态页面中的pdf文件存储在服务器中的链接很少。 我可以单击每个可以在浏览器中打开pdf文件的链接。 我提到了这个链接 但它没有像我预期的那样工作。

这是我的行动方法:

public ActionResult GetFileFromServer(string filename)
{
   string folderpath = StrGlobal.file_folder.ToString();
   string filepath = Path.Combine(folderpath, filename);
   filepath = Path.GetfullPath(filepath);

   return File(filepath, "application/pdf");
}

我的观点:

<p>
   @Html.ActionLink(
   linkText: "ABC Document",
   actionName:"GetFileFromServer",
   controllerName:"StaticPage",
   routeValues:new {filename = "ABC.pdf"},
   htmlAttributes:null
   )
</p>

如果我在此行中替换和硬核文件名:

string filepath = Path.Combine(folderpath, "ABC.pdf");

它将打开该特定的pdf文件。 否则我会收到错误说

Value cannot be null. Parameter name: path2

似乎值没有从视图传递到控制器。 我该如何解决这个问题?

 <a href="/staticpath/ABC.pdf" download> Donloadpdf </a> 

嗨,

我们可以通过使用html下载功能轻松解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM