maztt
maztt

Reputation: 12302

Making a downloadable link in ASP.NET MVC

<a href="../../App_Data/form.xml">Download Sample Form </a>

Why is this link not working?

Upvotes: 2

Views: 1807

Answers (2)

veggerby
veggerby

Reputation: 9020

Files in App_Data are not served via HTTP you should place the XML file outside App_Data, eg. in /Content

Alternatively you must create an Action that returns the file contents via File action result, e.g.

public ActionResult SampleForm() 
{
    return File(Server.MapPath("~/App_Data/form.xml"));
}

And then link via:

<%= Html.ActionLink("Download Sample Form", "SampleForm", "MyController") %>

Upvotes: 7

Matteo Mosca
Matteo Mosca

Reputation: 7458

If you mean constructing it using the MVC routing engine and helpers, the method Url.Content is what you're looking for.

Upvotes: 1

Related Questions