title: ASP.NET -- C# MVC5
body: <p>Basically I have something a site that <strong>a user inputs a image with a title</strong> and i want to display it on the website. That title for that image.</p>
  
  <p>Atm <strong>I'm saving to a folder and displaying all images</strong> but I cant display the title. It just doesnt appear when I do <code>&lt;h2&gt;@Html.DisplayFor(m =&gt; m.title)&lt;/h2&gt;</code></p>
  
  <p>Something like this: But I wanted the title of the post.
  <a href="https://i.gyazo.com/17828889116a77983f70fd8c8a4c2ebf.png" rel="nofollow noreferrer">https://i.gyazo.com/17828889116a77983f70fd8c8a4c2ebf.png</a></p>
  
  <p><strong><em>Maybe I need to save the image to the database? Please help me on this.</em></strong></p>
  
  <p>View:</p>
  
  <pre><code>    @foreach (var image in Model.Images)
  {
      &lt;h2&gt;@Html.DisplayFor(m =&gt; m.title)&lt;/h2&gt;
      &lt;div class="row"&gt;       
          &lt;div class="col-md-8 portfolio-item"&gt;
              &lt;img class="portrait" src="@Url.Content(image)" alt="Hejsan" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  }
  </code></pre>
  
  <p>Model</p>
  
  <pre><code> [Table("MemeImages")]
  public class UploadFileModel
  {
      [Key]
      [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
      public int id { get; set; }
  
      public string location { get; set; }
  
      public IEnumerable&lt;string&gt; Images { get; set; }
  
      public int contentLength { get; set; }
      public string contentType { get; set; }
  
      public string userID { get; set; }
  
      [Required]
      [Display(Name = "Describe your post...")]
      public string title { get; set; }
  
      public void SavetoDatabase(UploadFileModel file)
      {
          ApplicationDbContext db = new ApplicationDbContext();                    
          db.uploadedFiles.Add(file);
          db.SaveChanges();
      }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code> public class MemesController : Controller
  {
  
      private string memesDirectory = "~/Content/Images/Memes/";
  
      // GET: Memes/Upload
      public ActionResult Upload()
      {
          var uploadFile = new UploadFileModel();
          return View(uploadFile);
      }
  
      // GET: Memes/Hot
      public ActionResult Hot(UploadFileModel uploadFileModel)
      {
          //Select every image on the server memesdirectory and posts it
          uploadFileModel.Images = Directory.EnumerateFiles(Server.MapPath(memesDirectory)).Select(fn =&gt; memesDirectory + Path.GetFileName(fn));
          return View();
      }
  
      // GET: Memes/Trending
      public ActionResult Trending()
      {
          return View();
      }
  
      // GET: Memes/Fresh
      public ActionResult Fresh()
      {
          return View();
      }
  
      [HttpPost]
      public ActionResult Upload(UploadFileModel uploadModel)
      {         
          if(Request.Files.Count &gt; 0)
          {
              var file = Request.Files[0];
  
              if(file != null &amp;&amp; file.ContentLength &gt; 0)
              {
                  //saves image to the server
                  var fileName = Path.GetFileName(file.FileName);
                  var path = Path.Combine(Server.MapPath(memesDirectory), fileName);
                  file.SaveAs(path);
  
                  //saves image-related data to the database
                  uploadModel.userID = User.Identity.GetUserId();
                  uploadModel.location = path;
                  uploadModel.contentType = file.ContentType;
                  uploadModel.contentLength = file.ContentLength;
  
  
                  //saves to the database
                  uploadModel.SavetoDatabase(uploadModel);
              }
          }
          return RedirectToAction("Index", "Home");
      }
  }
  </code></pre>
  
  <p>}</p>