title: How to set the value of dropdown coming from model in ASP.NET MVC
body: <p>I am stuck at "how to set value in the dropdown to the value that is set in the model.</p>
  
  <p>I am adding what I have till now and what I have tried.</p>
  
  <p>So, I have a <code>PaymentFormMV</code> Model and it has another Model in it which is <code>PaymentCCMV</code> </p>
  
  <pre><code>public class PaymentFormMV
  {
      public PaymentCCMV CreditDetails { get; set; }
      public string ModelPropertyPrefixName
      {
          get
          {
              return this.ModelPropertyPrefix.Replace("_", ".");
          }
      }
  }
  public class PaymentCCMV
  {
      [Display(Name = "Expiration Date")]
      public int ExpirationMonth { get; set; }
  }
  </code></pre>
  
  <p><strong>cshtml file takes data from PaymentFormMV</strong></p>
  
  <pre><code>&lt;div class="form-group"&gt;
      @Html.LabelFor(model =&gt; model.CreditDetails.ExpirationMonth, htmlAttributes: new { @class = "control-label col-md-2 required" })
      &lt;div class="col-md-10"&gt;
          @Html.DropDownList(Model.ModelPropertyPrefixName + "CreditDetails.ExpirationMonth", Helpers.PossibleMonths,
          new { id = Model.ModelPropertyPrefix + "CreditDetails_ExpirationMonth", @class = "form-control", style = "width:70px;" })
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Helpers.PossibleMonths: displays all the months</strong></p>
  
  <pre><code>public static ICollection&lt;SelectListItem&gt; PossibleMonths
  {
      get
      {
          return new List&lt;SelectListItem&gt;()
          {
              new SelectListItem() { Text = "1 - Jan", Value = "1" },
              new SelectListItem() { Text = "2 - Feb", Value = "2" },
              new SelectListItem() { Text = "3 - Mar", Value = "3" },
              new SelectListItem() { Text = "4 - Apr", Value = "4" },
              new SelectListItem() { Text = "5 - May", Value = "5" },
              new SelectListItem() { Text = "6 - Jun", Value = "6" },
              new SelectListItem() { Text = "7 - Jul", Value = "7" },
              new SelectListItem() { Text = "8 - Aug", Value = "8" },
              new SelectListItem() { Text = "9 - Sep", Value = "9" },
              new SelectListItem() { Text = "10 - Oct", Value = "10" },
              new SelectListItem() { Text = "11 - Nov", Value = "11" },
              new SelectListItem() { Text = "12 - Dec", Value = "12" },
          };
      }
  }
  </code></pre>
  
  <p>Points: </p>
  
  <p>I am getting integer value <code>model.CreditDetails.ExpirationMonth = 2</code> (as per DB)</p>
  
  <p>But I don't know how to set it to the drop down. So when the screen loads I want that value to be tied to the dropdown. Please guide me. SO, if the value is 2 I should get something like <code>2 - Feb</code> in the Dropdown UI as mentioned in the Helper Method. I am a beginner so I might not be following the best practice so bear with me on this.</p>
  
  <p><strong>HTML GENERATED:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/8ozJp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8ozJp.jpg" alt="enter image description here"></a></p>