возьмите свою ссылку примерно так:
@Html.ActionLink(
"Download Image", // text to show
"Download", // action name
["DownloadManager", // if need, controller]
new { filename = "my-image", fileext = "jpeg" } // file-name and extension
)
и action-метод здесь:
public FilePathResult Download(string filename, string fileext) {
var basePath = Server.MapPath("~/Contents/Images/");
var fullPath = System.IO.Path.Combine(
basePath, string.Concat(filename.Trim(), '.', fileext.Trim()));
var contentType = GetContentType(fileext);
// The file name to use in the file-download dialog box that is displayed in the browser.
var downloadName = "one-name-for-client-file." + fileext;
return File(fullPath, contentType, downloadName);
}
private string GetContentType(string fileext) {
switch (fileext) {
case "jpg":
case "jpe":
case "jpeg": return "image/jpeg";
case "png": return "image/x-png";
case "gif": return "image/gif";
default: throw new NotSupportedException();
}
}
UPDATE:
фактически, когда файл отправляется в браузер, этот ключ / значение будет сгенерирован в http-header :
Content-Disposition: attachment; filename=file-client-name.ext
, который file-client-name.ext
- это name.extension , для которого вы хотите сохранить файл как в клиентской системе; например, если вы хотите сделать это в ASP.NET (нет mvc), вы можете создать HttpHandler , записать file-stream в Response , и просто добавьте указанный выше ключ / значение в http-header :
Response.Headers.Add("Content-Disposition", "attachment; filename=" + "file-client-name.ext");
только это, наслаждайтесь: D