2016-05-02 7 views
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ファイルは、次のリンクを持っている

私はまた、次のlinkisに変更し
<a href="~/Home/Download/@ViewBag.id" class="btn">Download zip</a> 

@Html.ActionLink("Download zip", "Download", new { [email protected], @class = "btn" }) 

<a href="@Url.Action("download","Home" , new { [email protected]})" class="btn"> Download zip</a> 

これでもエラーが発生します。

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

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

要求されたURL:/ホーム/ダウンロード/ 7

私は何をすべき?このエラーの場合、アクションはビューを返しませんか?

+0

を試してみてくださいすることができますが、 'ダウンロード()'メソッドはHomeController' 'に存在しないのか? –

+0

@StephenMueckeもちろん存在します!私は結果の種類のためにそれを考えると、関連するビューを見つけられないエラーが発生したときに私はそれを修正する方法がわからない!私は行動のためのビューを必要としません! –

+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); 
} 
+0

このメソッドが決してヒットしなかった場合、コードを変更することで可能な違いは何ですか? –