【问题标题】:How to create a button for downloading pdf file that is Present in solution explorer?如何创建一个按钮来下载解决方案资源管理器中存在的 pdf 文件?
【发布时间】:2017-10-11 02:38:47
【问题描述】:

我正在尝试在我的 ASP.NET CORE 的视图页面中创建一个按钮。

当用户单击该按钮时,解决方案中存在的 pdf 文件(sln) 应该下载给用户。

 I tried a href="location" inside button

 <a href="location" target="blank">download</a>

它不工作。

还有其他方法吗?

请帮帮我。

提前致谢。

【问题讨论】:

  • 你使用的是 webforms 还是 mvc?
  • 您究竟使用了什么作为“位置”,例如哪个文件名?
  • ASP.NET CORE@GeorgeWurthmann 和 @Moriarity 在我的 mvc 文件名 PDF.cshtml 中查看页面

标签: c# html pdf asp.net-core


【解决方案1】:

pdf 在您的文件结构中位于何处?

任何静态文件(例如此 pdf 文档)必须位于 dotnet 核心项目的 wwwroot 文件夹中。

此外,必须在 Startup.cs 文件的 Configure 方法中启用静态文件服务。

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseStaticFiles();
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
    });
}

【讨论】:

    【解决方案2】:

    Check HTML5 download attribute

    请务必检查浏览器支持。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-07
      • 2020-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-16
      • 1970-01-01
      • 2012-08-31
      相关资源
      最近更新 更多