0

我将如何在弹出窗口中显示 PDF/文档/文本文件而不是允许用户下载它?

这些文件路径存储在数据库表中,在我的 ASP.NET MVC 2.0 项目中,我有一个名为“文件”的文件夹,其中存储了我的实际文件。

我有一个 Telerik MVC 网格,其中有一个名为 AssociatedFiles 的列,在此列中有一个 ClientTemplate,例如“查看文件”。一旦有人单击此链接,与该 RowID 关联的实际文件应显示在弹出窗口中,而不是允许用户下载它。

使用 FilePathResult 我可以允许我的用户下载它,但我不想要这个。我希望用户在 PopUp Window 中查看该特定文件。

我为这个特定场景搜索了很多相关代码,但找不到任何有用的东西。请帮助我提供实际的工作代码。发送您的评论@ashes22@gmail.com

4

1 回答 1

1

将部分视图添加到名为“FilePopUp”的视图文件夹中。这里使用 Telerik Window Control

代码 :-

 <% Html.Telerik().Window()
            .Name("PopupWindow")
            //.Title("View PDF")
            //.Icon(Url.Content("~/Content/Common/Icons/favicon.png"), "favicon")
            .LoadContentFrom(Model.PDFFilePath).Modal(true)
            .Buttons(buttons => buttons.Close(Url.Action("Controller", "Action")))
            //.Buttons(buttons => buttons.Maximize(Url.Action("Controller")).Close(Url.Action("Controller", "Action")))
            .Scrollable(false)
            .Resizable()
            .Draggable(true)
            .Width(870)
            .Height(500)
            .Render();
    %>

在您的控制器中:-

            public ActionResult GetPdffile(string id)
    {
        try
        {
            FilePathAdmin filePath = new FilePathAdmin();
            filePath.ERAPDFFilePath = this.WorkerService.GetPdfFilepath(id);
           //string filepath = this.WorkerService.GetPdfFilepath(ID);
            return PartialView("PopUpWindow", filePath);

        }
        catch (Exception ex)
        {
            bool reThrow = ExceptionPolicyWrapper.HandleException(ex, ExceptionPolicies.MVCPolicy);
            if (reThrow)
                throw;
        }
        return null;
    }

在您的模型类中,创建另一个名为“FilePathAdmin”的类并在其中编写以下代码

           public class FilePathAdmin
{
    public string ERAPDFFilePath { get; set; }
}

就是这样..你完成了

于 2011-09-08T12:03:52.900 回答