title: View and display uploaded file in ASP.NET MVC5?
body: <p>Can anyone help me in my simple board problem?</p>
  
  <p>I created a project with ASP.NET MVC5 that take input file from a user, this is done for me.</p>
  
  <p>In the details view I want to create a link to that file.</p>
  
  <p>Please any help.</p>
  
  <p>This is my controller:</p>
  
  <pre><code>public ActionResult Details(string id)
  {
              if (id == null)
              {
                  return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
              }
  
              Employee employee = db.Employees.Find(id);
  
              if (employee == null)
              {
                  return HttpNotFound();
              }
  
              // to view the uploaded file
              return View(employee);
  }
  
  
  //POST Details
  
  // GET: Employees/Create
  public ActionResult Create()
  {
      return View();
  }
  
  // POST: Employees/Create
  // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
  // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
  [HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult Create([Bind(Include = "id,Region,Name,Position,Qualification,Major,Experience,JoinedDate,Extension,Mobile,OfficeNo,Work_Achivement")] Employee employee, HttpPostedFileBase CV)
  {
              if (ModelState.IsValid)
              {
                       if (CV != null &amp;&amp; CV.ContentLength &gt; 0)
                                {
                              // extract only the fielname
                              var fileName = Path.GetFileName(CV.FileName);
                              // store the file inside ~/Content/LearnObject-Repository folder
                              var path = Path.Combine(Server.MapPath("~/Content/CVs"), fileName);
                              CV.SaveAs(path);
                              var fileNameToSaveInDB = @"~/Content/CVs/" + fileName;
                          }
  
                  db.Employees.Add(employee);
                  db.SaveChanges();
                  return RedirectToAction("Index");
              }
  
              return View(employee);
  }
  
  // GET: Employees/Edit/5
  public ActionResult Edit(string id)
  {
      if (id == null)
      {
          return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
      }
  
      Employee employee = db.Employees.Find(id);
  
      if (employee == null)
      {
          return HttpNotFound();
      }
  
      return View(employee);
  }
  </code></pre>
  
  <p>and this is my view for details:</p>
  
  <pre><code>@model WebApplication1.Models.Employee
  
  @{
      ViewBag.Title = "Details";
  }
  
  &lt;h2 style="font-family:'Times New Roman', Times, serif"&gt;Employee Details&lt;/h2&gt;
  
  &lt;div&gt;
  
      &lt;hr /&gt;
      &lt;table class="table table-bordered"&gt;
          &lt;tr&gt;
              &lt;th width="250" &gt;
                  @Html.DisplayNameFor(model =&gt; model.Region)
              &lt;/th&gt;
  
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.Region)
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Name)
              &lt;/th&gt;
  
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.Name)
              &lt;/td&gt;
              &lt;/tr&gt;
  
          &lt;tr&gt;
  
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Position)
              &lt;/th&gt;
  
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.Position)
              &lt;/td&gt;
              &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Qualification)
              &lt;/th&gt;
  
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.Qualification)
              &lt;/td&gt;
              &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Major)
              &lt;/th&gt;
  
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.Major)
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Experience)
              &lt;/th&gt;
  
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.Experience)
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.JoinedDate)
              &lt;/th&gt;
  
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.JoinedDate)
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Extension)
              &lt;/th&gt;
  
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.Extension)
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Mobile)
              &lt;/th&gt;
  
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.Mobile)
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.OfficeNo)
              &lt;/th&gt;
  
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.OfficeNo)
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Work_Achivement)
              &lt;/th&gt;
  
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.Work_Achivement)
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.CV)
              &lt;/th&gt;
              &lt;td&gt;
                  @{
                      var name = Model.CV.FileName;
  
                      var link = @Url.Content("~/Content/CVs/") + name.Replace(" ", "%20") + ".pdf";
  
                      string tag = "&lt;a href=" + link + "&gt;" + name + "&lt;/a&gt;";
      //var x = fname.ToString();
  
                  }
              &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
  &lt;/div&gt;
  
  @{
      var diffrence = DateTime.UtcNow - Model.JoinedDate;
      var Total_Years = (diffrence.TotalDays / 365);
  
      var KSAUHSExperience = Math.Round(Total_Years,1);
  
      var Years = Math.Round(Model.Experience + Total_Years);
      var months = Math.Round(Years % 12);
  
      @*&lt;text&gt;Total Experience: &lt;/text&gt;@Html.DisplayTextFor(model =&gt; Years)&lt;text&gt; Years and &lt;/text&gt;    @Html.DisplayTextFor(model =&gt; months)&lt;text&gt; month &lt;/text&gt;; &lt;br /&gt;*@
  
  
  
      &lt;p style="font-family:'Times New Roman', 'Times', 'serif';font-size:medium"&gt;Total Experience:@Html.DisplayTextFor(model =&gt; Years)Years and @Html.DisplayTextFor(model =&gt; months) Monthes&lt;/p&gt;
  
      &lt;p style="font-family:'Times New Roman', 'Times', 'serif';font-size:medium"&gt; Experience at ksau-hs @Html.DisplayTextFor(model =&gt; KSAUHSExperience)&lt;/p&gt;
  
          @*&lt;text&gt; experience in ksau-hs &lt;/text&gt;   @Html.DisplayTextFor(model =&gt; KSAUHSExperience)*@  
       }
  &lt;p&gt;
  
      @Html.ActionLink("Back to List", "Index")
  &lt;/p&gt;
  </code></pre>
  
  <p>below the model</p>
  
  <pre><code>namespace WebApplication1.Models
  {
  
      public enum Qualification
      {
          //Select,
          Diploma,
          Bacholer, Master, PhD
      }
  
  
      public enum Major
      {
          //Select,
          [Display(Name = "Software Engneering")]
          SoftwareEngneering,
          [Display(Name = "Information System")]
          InformationSystem,
          [Display(Name = "Information Technology")]
          InformationTechnology,
  
          [Display(Name = "Computer Engneering")]
          ComputerEngneering,
          [Display(Name = "Computer Science")]
          ComputerScience,
          [Display(Name = "Computer Security")]
          ComputerSecurity,
          [Display(Name = "Health Informatics")]
          HealthInformatics,
          [Display(Name = "Mangement Information System")]
          MangementInformationSystem,
          [Display(Name = "Telecommuncation Engneering")]
          TelecommuncationEngneering,
          [Display(Name = "Graphic Design")]
          GraphicDesign
  
      }
      public class Employee
      {
  
          [HiddenInput]
          public string Region { get; set; }
          public string id { get; set; }
  
  
  
  
  
  
  
          [Required]
          public string Name { get; set; }
  
          [Required]
          public string Position { get; set; }
  
  
  
          [DisplayFormat(NullDisplayText = "Select")]
          [Required]
          public Qualification? Qualification { get; set; }
          [DisplayFormat(NullDisplayText = "Select")]
          [Required]
          public Major? Major { get; set; }
  
  
          public int Experience { get; set; }
  
  
          [DataType(DataType.Date)]
          public DateTime JoinedDate { get; set; }
  
  
          public string Extension { get; set; }
  
          public string Mobile { get; set; }
  
  
  
  
  
  
          [Display(Name = "Office#")]
  
          public string OfficeNo { get; set; }
  
  
  
  
          [Display(Name = "Work Achivement")]
  
          [DataType(DataType.MultilineText)]
          public string Work_Achivement { get; set; }
  
          [NotMapped]
          [Display(Name = "C.V")]
          [DataType(DataType.Upload)]
  
          public HttpPostedFileBase CV { get; set; }
          [NotMapped]
          [Display(Name = "Personal Photo")]
          [DataType(DataType.Upload)]
          public HttpPostedFileBase PersonalPhoto { get; set; }
  
  
  
      }
  
  }
  </code></pre>
  
  <p>Thanks a lot </p>