title: Select a images from a folder and then display it in a selectlist or just display it
body: <p>Hi guys im really new at this!</p>
  
  <p>I have been stuck here for along time. Please i really need your help. Thanks!</p>
  
  <p>My question for you are. How can i display all of my images to a Selectlist or dropdownlist in MVC and then post it on the site? I got a database with PicID, PicTitle etc..</p>
  
  <p>I want to display or show the images from that folder and then be enable to choose a picture and then display it in the view. </p>
  
  <p>In my Create View i have:</p>
  
  <pre><code>&lt;h2&gt;Create&lt;/h2&gt;
  </code></pre>
  
  <p>@using (Html.BeginForm()) {
      @Html.ValidationSummary(true)</p>
  
  <pre><code>&lt;fieldset&gt;
      &lt;legend&gt;Picture&lt;/legend&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.PicTitle)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.PicTitle)
          @Html.ValidationMessageFor(model =&gt; model.PicTitle)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.PicUrl)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.Action(Model.PicID)
          @Html.ValidationMessageFor(model =&gt; model.PicID)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.PicAltText)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.PicAltText)
          @Html.ValidationMessageFor(model =&gt; model.PicAltText)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.PicDesc)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.PicDesc)
          @Html.ValidationMessageFor(model =&gt; model.PicDesc)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.PicPrio)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.PicPrio)
          @Html.ValidationMessageFor(model =&gt; model.PicPrio)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.CatID, "Category")
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.DropDownList("CatID", String.Empty)
          @Html.ValidationMessageFor(model =&gt; model.CatID)
      &lt;/div&gt;
  
      &lt;p&gt;
          &lt;input type="submit" value="Create" /&gt;
      &lt;/p&gt;
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>And in my Controller:</p>
  
  <pre><code>        public ActionResult Create()
      {
          ViewBag.CatID = new SelectList(db.Categories, "CatID", "CatName");
          return View();
      }
  
      //
      // POST: /Picture/Create
  
  
  
      [HttpPost]
      public ActionResult Create(Picture picture, HttpPostedFileBase file)
      {
          if (file != null &amp;&amp; file.ContentLength &gt; 0)
          {
              var FileName = string.Format("{0}.{1}", Guid.NewGuid(), file.ContentType);
              var path = Path.Combine(Server.MapPath("~/Images_upload"), FileName);
              file.SaveAs(path);
          }
          if (ModelState.IsValid)
          {
              db.Pictures.AddObject(picture);
              db.SaveChanges();
              return RedirectToAction("Index");
          }
  
          ViewBag.CategoryID = new SelectList(db.Pictures, "PicID", "PicTitle", picture.PicID);
          return View(picture);
      }
  </code></pre>
  
  <p>Please help me and thanks to all.</p>