我有一个用ASP.NET MVC编写的文件上传程序。它目前在我的本地开发机器上,并且我想知道如何(如果有可能)为每个上传的文件生成链接,因此当它被点击时,该项目被显示/下载等。本地文件的映射路径ASP.NET/MVC
当前代码/标记,处理显示文件列表:
<table>
<tr>
<th></th>
<th>
Name
</th>
<th>
Length
</th>
<th></th>
</tr>
<%
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "uploads");
foreach (var file in Directory.GetFiles(path))
{
var item = new FileInfo(file);
%>
<tr>
<td></td>
<td>
<%=Html.Encode(Path.GetFileName(item.Name))%>
</td>
<td>
<%=Html.Encode(item.Length >= 1024 ? item.Length/1024 + " kilobytes" : item.Length + " bytes")%>
</td>
<td>
// This is the line in question. Does not work as-is.
<a href="<%= item.FullName %>"><%= Html.Encode(Path.GetFileName(item.Name)) %></a>
</td>
</tr>
<% } %>
</table>
我想我将不得不改变周围的文件处理代码,一旦此去住,但现在这已经足够了。建议也欢迎:)
谢谢!
+1正是我想要的(对于MVC3 - 链接到elmah.axd),谢谢! – ashes999 2011-12-28 21:42:11