Download File using MVC Core -


i cannot find reference downloading file using mvc core.

we have single exe file members download our website. in past have put

<a href=(file path)> download < /a> our users click. equivalent in mvc core along lines of

<a href=@viewdata["downloadlink"]> download < /a> 

with downloadlink populated file path.

public class downloadcontroller : controller {     [httpget]     public iactionresult index()     {         viewdata["downloadlink"] = ($"~/downloads/{v9.version}.exe");         return view();     } } 

`

the link <a href=@viewdata["downloadlink"]> download < /a> gets correct path, when clicked renders path in address bar. there simple way set download link?

i used this answer posted @tieson t come solution

    public fileresult download()     {         var filename = $"{v9.version}.exe";         var filepath = $"downloads/{filename}";         byte[] filebytes = system.io.file.readallbytes(filepath);         return file(filebytes, "application/x-msdownload", filename);     } 

the view now

<a asp-action="download" asp-> download 

@ageonix correct not requiring ~ wwwroot


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -