title: How to download files in mvc3?
body: <p>I'm programming a web site which needs to be capable of upload and download all kinds of files. Such as .php, .rar, .jpg, .cs, .pdf, .txt and so. When I use plain html like:</p>
  
  <pre><code> &lt;a href="@Model.dList[i].filePath"&gt;download&lt;/a&gt;
  </code></pre>
  
  <p>it shows the content of the txt and jpeg files in the browser but I don't want this to happen. I'm guessing I need to use controller and write some piece of code for it. I did some research and figured out it has something to do with contentType attribute of files. I played with them a bit and wrote a function</p>
  
  <p>Controller:</p>
  
  <pre><code>public FileResult DownloadDoc(int dID)
      {
          string filePath = getFilePath(dID);
          string contentType = getContentType(dID);
          filePath = Path.Combine(Server.MapPath(dr.GetString("FilePath")), dr.GetString("FileName"));
          return File(filePath, contentType);
      }
  </code></pre>
  
  <p>View:   </p>
  
  <pre><code>    @Html.ActionLink("Download", "DownloadDoc", new { dID = @Model.dList[i].documentationID })
  </code></pre>
  
  <p>With this function a file is downloaded but it's name is DownloadDoc always and without any extension. I'm stuck here.</p>
  
  <p>Should I do anything fancy while i'm uploading the files? By the way, after I upload the files their paths, contenttypes and file names are stored in database. What should I do?</p>