I am new to ASP.NET MVC and I'am trying to link to downloadable files (.zip, .mp3, .doc, etc).
I have the following view: ProductName
which maps to: http://domain/ProductName
I have a .zip
file that must map to URL http://domain/ProductName/Product.zip
Where do I place this .zip
file in the MVC folder structure?
How do I add link to this .zip
file in MVC? Is there a Url.* method that do this?
You can use FilePathResult or Controller.File method.
protected internal virtual FilePathResult File(string fileName, string contentType, string fileDownloadName) {
return new FilePathResult(fileName, contentType) { FileDownloadName = fileDownloadName };
}
Sample code action method.
public ActionResult Download(){
return File(fileName,contentType,downloadFileName);
}
Hope this code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With