创建文件的下载链接使用模型MVC3剃刀查看 [英] Creating File Download Links MVC3 Razor View with Model
问题描述
我试图在我看来,以创建链接,这样最终用户可以在我的模型下载文件。在Internet Explorer中,我可以右键单击并从链接下载,但我不能离开点击(它不打开文件)。火狐给了我,当我点击它一点儿也不知道怎么打开这个地址的文件,因为该协议(四)不与任何程序关联的消息。
下面是我正在创建的链接。
@ {
的foreach(在item.files VAR EpubFile)
{
如果(File.Exists(System.Configuration.ConfigurationManager.AppSettings [UploadFileDirectory] + EpubFile.FileReference))
{
字符串链接= System.Configuration.ConfigurationManager.AppSettings [UploadFileDirectory] + EpubFile.FileReference;
&所述; A HREF =@链接> @ EpubFile.OriginalFileName&下; / A>
}
}
}
请确保该链接是与pfixed $ P $ 的http://
是全部或部分路径URL形式,而不是在文件名的形式。例如, C:\\的Inetpub \\ wwwroot的\\富\\文件\\ myfile.txt的
应 /files/myfile.txt
。您可以使用使用Server.Mappath
来获得您的Web应用程序根目录下的文件的相对路径。
I am attempting to create links in my view so the end user can download the files in my model. In internet explorer I can right click and download from the link but I cannot left click (it does not open the file). Firefox gives me a message when I click the file that it does'nt know how to open this address, because the protocol (d) isn't associated with any program.
Here is how I am creating the link.
@{
foreach (var EpubFile in item.files)
{
if(File.Exists(System.Configuration.ConfigurationManager.AppSettings["UploadFileDirectory"] + EpubFile.FileReference))
{
string link = System.Configuration.ConfigurationManager.AppSettings["UploadFileDirectory"] + EpubFile.FileReference;
<a href="@link">@EpubFile.OriginalFileName</a>
}
}
}
Make sure the link is prefixed with http://
and is a full or partial path in URL form, not in filename form. E.g., c:\inetpub\wwwroot\foo\files\myfile.txt
should be /files/myfile.txt
. You can use Server.MapPath
to obtain the relative path of a file under your web application root.
这篇关于创建文件的下载链接使用模型MVC3剃刀查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!