0

ビューを返さない次のアクションがあります

  public FileResult Download(int? id)
    {
        var files = from p in _db.tbl_Pdfs
                    where p.PaperId == id
                    select p.FileName;

        var archive = Server.MapPath("~/Content/Zip/archive.zip");
        var temp = Server.MapPath("~/Content/Temp");

        // clear any existing archive
        if (System.IO.File.Exists(archive))
        {
            System.IO.File.Delete(archive);
        }
        // empty the temp folder
        Directory.EnumerateFiles(temp).ToList().ForEach(f => System.IO.File.Delete(f));

        // copy the selected files to the temp folder

        foreach (string name in files)
        {
            string sourceFile = System.IO.Path.Combine("~/Content/Pdf", name);
            System.IO.File.Copy(sourceFile, "~/Content/Temp", true);
        }
        // create a new archive
        ZipFile.CreateFromDirectory(temp, archive, CompressionLevel.Fastest, true);



        return File(archive, "application/zip", "archive.zip");
    }

また、zipファイルをダウンロードするための次のリンクもあります

<a href="~/Home/Download/@ViewBag.id" class="btn">Download zip</a>

また、次のリンクに変更します

   @Html.ActionLink("Download zip", "Download", new { id=@ViewBag.id, @class = "btn" })

 <a href="@Url.Action("download","Home" , new { id=@ViewBag.id})" class="btn"> Download zip</a>

しかし、それでもエラーが発生します!

リソースが見つかりません。

説明: HTTP 404。探しているリソース (またはその依存関係の 1 つ) は、削除されたか、名前が変更されたか、一時的に利用できない可能性があります。次の URL を見直して、スペルが正しいことを確認してください。

要求された URL: /Home/Download/7

私は何をすべきか?このエラーの場合、アクションはビューを返さないのですか?

4

1 に答える 1

0

以下を変更して試していただけますか

foreach (string name in files)
{
    string sourceFile = Server.MapPath( System.IO.Path.Combine("~/Content/Pdf", name));
    System.IO.File.Copy(sourceFile, Server.MapPath(System.IO.Path.Combine("~/Content/Temp", name)), true);
}
于 2016-05-02T05:48:36.963 に答える