title: DropDownList - How to add SelectListItem ASP.NET MVC
body: <p>I have an DropDownList ,which is showing list of Status,but when i Select an item from DropDownlist and than i Checked HTML Markup i can see there isnt Selected attr  and than i researched and find out I need SelectListItem in my Controller and than i tried to implement it in my Controller,but i got some errors :) as usually i implement DropDown in my Razor View (static) , but this time which is first time :) i want implement in my Controller so it becomes dynamic.<br>
  Can anyone point me in right direction :)<br>
  Thanks in advance :)</p>
  
  <p>Controller:</p>
  
  <pre><code>    //DropDown
      public List&lt;VMRMA.NameStatusDropDown&gt; GetStatusForDropDown()
      {
  
          List&lt;VMRMA.NameStatusDropDown&gt; result = new List&lt;VMRMA.NameStatusDropDown&gt;();
  
          var obj = db.RMAStatus.Select(u =&gt; u).ToList();
  
  
          if (obj != null &amp;&amp; obj.Count() &gt; 0)
          {
              foreach (var data in obj)
              {
                  VMRMA.NameStatusDropDown model = new VMRMA.NameStatusDropDown();
                  model.Status = data.Status;
                  model.ID = data.ID;
                  result.Add(model);
              }
          }
  
          return result;
  
     }
  
      //Dropdown runs in this Action
      public ActionResult RMA ()
      {
        VMRMA model = new VMRMA();
        model.NameStatusDropDowns = GetStatusForDropDown();
  
       //RMA query and some an other stuff
  
       return View(model);
  
      }
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre><code>    public class VMRMA
      {
  
          public List&lt;NameStatusDropDown&gt; NameStatusDropDowns { get; set; }
  
  
          //DropDown
          public class NameStatusDropDown
          {
              public NameStatusDropDown()
              {
  
              }
              public NameStatusDropDown(int ID, string Status)
              {
                  this.ID = ID;
                  this.Status = Status;
  
  
              }
  
              public int ID { get; set; }
  
  
     public string Status { get; set; }
  
  
      }
  
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@using ModelNamespace.Models
  @model VMRMA
  
  &lt;form&gt;
  &lt;div class="form-group"&gt;
  &lt;label class="form-control-label"&gt;Select a status&lt;/label&gt;
  &lt;br /&gt;
  &lt;select&gt;
  
  &lt;option&gt;Select&lt;/option&gt;
  @foreach (var item in Model.NameStatusDropDowns)
  {                                        
    &lt;option value="@item.ID"&gt;@item.Status&lt;/option&gt;
  }
  &lt;/select&gt;
  
  &lt;/div&gt;
    &lt;div class="form-group"&gt;
    &lt;input type="submit" value="Send data" class="btn btn-primary"&gt;                                 
   &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>HTML Markup:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
  &lt;label class="form-control-label"&gt;Select a status&lt;/label&gt;
  &lt;br&gt;
   &lt;select&gt;
  &lt;option&gt;Select&lt;/option&gt;
  &lt;option value="1"&gt;Sendt&lt;/option&gt;
  &lt;option value="2"&gt;Under behandling&lt;/option&gt;
  &lt;option value="3"&gt;Blive behandlet&lt;/option&gt;
  &lt;option value="4"&gt;Modtaget&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;/div&gt;
  </code></pre>