title: How to set default value to select list in MVC during run time
body: <p>I have view in which it loop through the model and display the details in editable mode. One of the model value is from a select list like below</p>
  
  <pre><code>@if (Model != null)
      {
      for (int i = 0; i &lt; Model.provider_service_dtls.Count; i++)
       {
      &lt;tr&gt;
      &lt;td&gt; @Html.DropDownListFor(m =&gt; m.provider_service_dtls[i].activity_code_type,
   (SelectList)@ViewBag.activity_code_type, "--- Select Activity Code Type ---", new { @class = "m-wrap" })&lt;/td&gt;
      &lt;td&gt;@Html.TextBoxFor(m =&gt; m.provider_service_dtls[i].activity_name)&lt;/td&gt;    
      &lt;/tr&gt;
  
      }
      } 
  </code></pre>
  
  <p>Here the <code>ViewBag.activity_code_type</code> contain the values <code>Internal &amp; Standard</code> when submitting if user selected <code>Internal</code> its value <code>1</code> will pass to controller and if <code>Standard</code> it will be <code>2</code> and here the default value will be <code>"--- Select Activity Code Type ---"</code></p>
  
  <p><img src="https://i.stack.imgur.com/bIyl3.jpg" alt="enter image description here"></p>
  
  <p>Now when i open the same request in edit mode if the model value for <code>provider_service_dtls[i].activity_code_type</code> is <code>1</code> the select list should be default select as <code>Internal</code> and <code>Standard</code> if it is <code>2</code>.</p>
  
  <p>I coded like this</p>
  
  <pre><code>    @Html.DropDownListFor(m =&gt; m.provider_service_dtls[i].activity_code_type,
   (SelectList)@ViewBag.activity_code_type, Model.provider_service_dtls[i].activity_code_type)
  </code></pre>
  
  <p>But it is not working as expected it is giving the result as below picture</p>
  
  <p><img src="https://i.stack.imgur.com/e92e2.jpg" alt="enter image description here"></p>
  
  <p>Here it should default selected <code>Internal</code>. What is the change to do achieve the same?</p>
  
  <p><strong>Edited</strong></p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public partial class provider_service_dtls
      {
          [Key]
          [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
          public long service_id { get; set; }
  
          public long preapproval_id { get; set; }
  
          public string activity_code_type { get; set; }
          public string activity_type { get; set; }
  
          public string activity_type_name { get; set; }
  
  
          public string activity_code { get; set; }
          public string activity_name { get; set; }
          public string internal_activity_code { get; set; }
          public string internal_activity_name { get; set; }
  
  
          [ForeignKey("preapproval_id"), InverseProperty("provider_service_dtls")]
          public virtual provider_preapproval preapproval { get; set; }
  
  
      }
  </code></pre>
  
  <p><strong>Editor template</strong></p>
  
  <pre><code>@model Provider.Models.provider_preapproval
  @Html.DropDownListFor(m =&gt; m.activity_code_type, (SelectList)ViewData["options"])
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <p>Inside the for loop i coded like this</p>
  
  <pre><code>  @Html.EditorFor(m =&gt; m.provider_service_dtls,
  new { options = (SelectList)@ViewBag.activity_code_type })
  </code></pre>
  
  <p>I am getting an error</p>
  
  <blockquote>
    <p>'System.Web.Mvc.HtmlHelper' does
    not contain a definition for 'EditorFor' and the best extension method
    overload
    'System.Web.Mvc.Html.EditorExtensions.EditorFor(System.Web.Mvc.HtmlHelper,
    System.Linq.Expressions.Expression>,
    string, object)' has some invalid arguments</p>
  </blockquote>