【发布时间】:2013-09-27 11:16:30
【问题描述】:
我绝对是 C# 编程的初学者,但遇到了一个愚蠢的问题。我只喜欢下载文件,这些文件位于带有 WebClient.DownloadFile 的临时目录中。 代码是(操作以单击页面上两个按钮之一的按钮开始):
[HttpPost]
[MultiButton(MatchFormKey = "action", MatchFormValue = "ABC")]
public ActionResult ABC(TestFormModel model)
{
string fileName = model.resultLink;
try
{
string tempPath = System.IO.Path.GetTempPath();
System.IO.Directory.SetCurrentDirectory(tempPath);
fileName = System.IO.Path.Combine(tempPath, fileName);
Uri uri = new Uri(fileName);
WebClient webClient = new WebClient();
webClient.DownloadFile(uri, "FFF");
}
catch (Exception ex)
{ ... }
return View();
}
现在我预计(阅读文档中的“将具有指定 URI 的资源下载到本地文件。”)来自浏览器的下载对话框将提示。但什么也没有发生。也不例外,没有下载对话框。我的代码有什么问题?
非常感谢!
【问题讨论】:
标签: c# asp.net-mvc razor download webclient