考虑一个必须为网站用户提供帮助的UserGuide PDF文件。
以下是视图中的链接:
@Html.ActionLink("User Guide","Help","Portal")
返回文件的控制器:
public ActionResult Help()
{
string path = Server.MapPath("~/Content/UserGuide.pdf");
var fileBytes = System.IO.File.ReadAllBytes(path);
var responseFile = new FileContentResult(fileBytes, "application/pdf")
{
FileDownloadName = "Guide.pdf"
};
return responseFile;
}
但是在这里,用户点击链接后,浏览器会提示下载文件,但更好的方法是,当用户点击链接时,PDF页面会显示在浏览器中。就像一个网页!任何机构都能提到实现这一目标的最佳方法吗?