問題:我從數據庫中其ID命名的文件。當有人想減少它時,我需要將它改爲它的真名。服務器上的文件看起來像例如:http://localhost:34256/Content/uploads/23。因此,例如我的文件名是,但我需要將其更改爲textfile1.txt。在MVC3下載更改文件名
我已創建了這些文件的列表中的部分觀點:
@foreach (var item in Model)
{
<a href="/Content/uploads/@item.Id" title="@Html.Encode(item.FileName)">
<img src="@item.IcoSrc" /><br />
@item.FileName
</a>
}
哪裏@item.FileName
是文件的真實姓名。當有人從該列表下載文件,他得到的文件名爲@ item.Id,而不是@ item.FileName。我該如何改變它?
我正在使用MVC3和.NET framevork 4.
任何幫助非常感謝!
您可以在此[文章]通過HTTP標頭更改文件名,如(HTTP:/ /stackoverflow.com/questions/93551/how-to-encode- content-disposition-header-in-http) – Madd0g
Content-Disposition可用於指定文件名。看看http://stackoverflow.com/questions/5826649/returning-a-file-to-view-download-in-mvc –