如何将FilePathResult内容返回到MVC中的View

时间:2013-09-11 21:45:19

标签: asp.net-mvc rendering asp.net-mvc-routing html-helper

我有一个View,我想使用Controller.Example中另一个方法的返回值:

public class PdfController : Controller
    {
        //
        // GET: /Pdf/

        public ActionResult Index()
        {
            return View();
        }

        public FileResult PdfAsContent()
        {
            return File(@"C:\Users\...\english.pdf","application/pdf");
        }
    }

当我导航到 localhost / Pdf / PdfAsContent 时,它成功加载了PDF的内容,但我想将其作为View的一部分加载。我希望有一个lable并在其下面显示: localhost / Pdf / PdfAsContent

显示的内容

我尝试过:

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
<div>
    @Url.Action("PdfAsContent")
</div>

但它返回: 指数 PDF / PdfAsContent

1 个答案:

答案 0 :(得分:0)

您甚至可以使用Google Docs Viewer。您需要在网址中设置embedded=true

例如,如果您想在网址http://research.google.com/archive/bigtable-osdi06.pdf上查看PDF,则可以使用以下网址:http://docs.google.com/viewer?url=http%3A%2F%2Fresearch.google.com%2Farchive%2Fbigtable-osdi06.pdf

  • 所有查看器网址都应使用路径http://docs.google.com/viewer。此路径接受两个参数:
  • url:要查看的文档的URL。这应该是URL编码。
  • embedded:如果设置为true,则查看器将使用嵌入式模式界面。
相关问题