ASP.NET MVC 在新文件中打开文件 window
ASP.NET MVC open file in new window
我创建了一个 MVC Web 应用程序。
当用户单击页面上的 'View' 按钮时,我需要打开 pdf 文件。
存储pdf的文件路径是从数据库中读取的,它是c上的一个文件:如何在我的代码中打开它?
我有这个代码:
@Html.ActionLink("Read", "ViewOnline", new { controller = "Home", id = item.Id }, new { target = "_blank" }, new { @class = "btn btn-default" })
还有我的控制器
public ActionResult ViewOnline(int id)
{
string link = BookBUS.Instance.GetBooks().Find(x => x.BookID == id).FilePath;
if (link != null)
{
TempData["Embed"] = VirtualPathUtility.ToAbsolute(link);
}
}
您正在为 HTML 个属性创建两个单独的对象:
new { target = "_blank" }, new { @class = "btn btn-default" }
我什至不确定 ActionLink
方法会调用什么重载。但是可以肯定的是,这两个单独的方法参数不会在内部组合用于 HTML 属性。
为 HTML 个属性创建一个对象:
new { target = "_blank", @class = "btn btn-default" }
然后应该使用 the correct method overload。
我创建了一个 MVC Web 应用程序。 当用户单击页面上的 'View' 按钮时,我需要打开 pdf 文件。 存储pdf的文件路径是从数据库中读取的,它是c上的一个文件:如何在我的代码中打开它?
我有这个代码:
@Html.ActionLink("Read", "ViewOnline", new { controller = "Home", id = item.Id }, new { target = "_blank" }, new { @class = "btn btn-default" })
还有我的控制器
public ActionResult ViewOnline(int id)
{
string link = BookBUS.Instance.GetBooks().Find(x => x.BookID == id).FilePath;
if (link != null)
{
TempData["Embed"] = VirtualPathUtility.ToAbsolute(link);
}
}
您正在为 HTML 个属性创建两个单独的对象:
new { target = "_blank" }, new { @class = "btn btn-default" }
我什至不确定 ActionLink
方法会调用什么重载。但是可以肯定的是,这两个单独的方法参数不会在内部组合用于 HTML 属性。
为 HTML 个属性创建一个对象:
new { target = "_blank", @class = "btn btn-default" }
然后应该使用 the correct method overload。