title: Select ENUM Tag Helper in ASP.NET Core MVC
body: <p>I need some help with an ENUM dropdown using Tag Helper.</p>
  
  <p>I found lots exemples binding a model to  Selectlist and some using ENUM but all of them, about CREATE action, and Im facing problems with EDIT action.</p>
  
  <p>MY MODEL</p>
  
  <pre><code> public class ProspectLog
      {
          public int Id { get; set; }
          public int IdProspect { get; set; }
          public int IdEmpresa { get; set; }
          public DateTime Criado { get; set; }
          public string Usuario { get; set; }
          public string Descricao { get; set; }
  
          public ETipoLog TipoLog { get; set; }
  
          public enum ETipoLog
          {
              [Display(Name = "CADASTRO")]
              Cadastro = 0,
              [Display(Name = "CONTATO")]
              Contato = 1,
              [Display(Name = @"TROCA ETAPA")]
              Troca = 2,
              [Display(Name = @"QUALIFICAÇÃO")]
              Qualifica = 3,
              [Display(Name = @"EDIÇÃO")]
              Edicao = 4
          }
      }
  </code></pre>
  
  <p>On my old project based on MVC5 I just used this on my View and it was enough.</p>
  
  <p>DROPDOWN</p>
  
  <pre><code>&lt;div class="form-group col-sm-6"&gt;
     &lt;label style="font-weight: bolder" for="txtSituacao"&gt;Situação&lt;/label&gt;
     @Html.EnumDropDownListFor(model =&gt; model.Situacao, htmlAttributes: new { @class = "form-control" })
     @Html.ValidationMessageFor(model =&gt; model.Situacao, "", new { @class = "text-danger" })
  &lt;/div&gt;
  </code></pre>
  
  <p>I tried with difent ways and I coudnt set the dropdown with database item select on Edit action. I tried this way:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;label asp-for="TipoLog" class="col-md-2 control-label"&gt;&lt;/label&gt;
      &lt;div class="col-md-10"&gt;             
           &lt;select asp-for="TipoLog" class="form-control"&gt;&lt;/select&gt;
           &lt;span asp-validation-for="TipoLog" class="text-danger"&gt;&lt;/span&gt;
       &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I also tried like that:</p>
  
  <pre><code> &lt;div class="form-group"&gt;
       &lt;label asp-for="TipoLog" class="col-md-2 control-label"&gt;&lt;/label&gt;
       &lt;div class="col-md-10"&gt; 
            &lt;select asp-for="TipoLog" asp-items="Html.GetEnumSelectList&lt;TipoLog&gt;()"&gt;&lt;/select&gt;
             &lt;span asp-validation-for="TipoLog" class="text-danger"&gt;&lt;/span&gt;
        &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>But it ran me to an compilation error:
  <a href="https://i.stack.imgur.com/emXma.png" rel="noreferrer"><img src="https://i.stack.imgur.com/emXma.png" alt="enter image description here"></a></p>
  
  <p>I also tryed to bind a model a list to a ViewBag on my controller, this way:</p>
  
  <p>CONTROLLER:</p>
  
  <pre><code>ViewBag.Log = new SelectList(lista, "Id", "Nome");
  </code></pre>
  
  <p>VIEW:</p>
  
  <pre><code> &lt;div class="form-group col-sm-2"&gt;
        &lt;label asp-for="TipoLogo" class="col-md-2 control-label"&gt;&lt;/label&gt;
        &lt;select asp-for="TipoLogo" asp-items="ViewBag.Log" class="form-control"&gt;&lt;/select&gt;
         &lt;span asp-validation-for="TipoLogo" class="text-danger"&gt;&lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Its worked partially, the drop down listed the items, but not selecting the correct item from database. it show the first on the list as selected.</p>