Download-Datei in ASP.NET Kern MVC

Komplett neu auf .Net-core aus MVC5, so wie funktioniert download-Datei arbeitet .NET-Core? Ich habe versucht aufzuschreiben-code, aber es hat Fehler. Vielen Dank im Voraus an die Helfer.

Controller

public ActionResult Download()
    {
        string[] files = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
        for (int i = 0; i < files.Length; i++)
        {
            files[i] = Path.GetFileName(files[i]);
        }
        ViewBag.Files = files;
        return View();
    }

    public FileResult DownloadFile(string fileName)
    {
        var filepath = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
        return File(filepath, LineMapping.GetMimeMapping(filepath), fileName);
    }

Ansicht

  <h2>Downloads</h2>
 <table>
 <tr>
    <th>File Name</th>
    <th>Link</th>
 </tr>
 @for (var i =0; i <= Model.Count -1; i++) {
    <tr>
        <td>
            @Model[i].ToString()
        </td>
        <td>     
            @Html.ActionLink("Download", "Download", new  { ImageName=@Model[i].ToString() })           
        </td>
    </tr>
}

InformationsquelleAutor Priyanshu | 2016-09-09
Schreibe einen Kommentar