title: Adding custom animation/CSS to @Html.DropDownListFor in MVC
body: <p>I'm trying to add some custom CSS to an MVC drop down list in order to change the appearance and animate it, which is all done using the classes. If I use a fixed list of items hard-coded in the page it works fine, but I can't figure out how to get the values to show up from the DropDownListFor. Here are three examples (using the 'User Level' dropdown on this particular form):</p>
  
  <p>This one works but looks bad:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      @Html.LabelFor(model =&gt; model.RoleID, "User Level", htmlAttributes: new { @class = "control-label col-md-2" })
      &lt;div class="col-md-10"&gt;
           @Html.DropDownListFor(model =&gt; model.RoleID, (SelectList)ViewBag.Roles, new { @Style = "width:290px", @tabindex = "13" })
           @Html.ValidationMessageFor(model =&gt; model.RoleID, "", new { @class = "text-danger" })
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This one looks and behaves how I want it to but only with fixed values:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;div class="control-label col-md-2"&gt;User Level&lt;/div&gt;
      &lt;div class="col-md-10"&gt;
          &lt;div class="btn-group m-b-5"&gt;
              &lt;button type="button" class="btn btn-sm dropdown-toggle" data-toggle="dropdown"&gt;Please select a user level&lt;/button&gt;
              &lt;ul class="dropdown-menu animated flipInX"&gt;
                  &lt;li&gt;&lt;a href="#"&gt;Action&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#"&gt;Another action&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#"&gt;Something else here&lt;/a&gt;&lt;/li&gt;
                  &lt;li class="divider"&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#"&gt;Separated link&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This one I've tried to combine the two and it doesn't show anything in the dropdown when clicked, but looks correct on the page. The drop down isn't empty, there is simply nothing displayed at all when clicked:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      @Html.LabelFor(model =&gt; model.RoleID, "User Level", htmlAttributes: new { @class = "control-label col-md-2" })
      &lt;div class="col-md-10"&gt;
          &lt;div class="btn-group m-b-5"&gt;
              &lt;button type="button" class="btn btn-sm dropdown-toggle" data-toggle="dropdown"&gt;Please select a user level
                  @Html.DropDownListFor(model =&gt; model.RoleID, (SelectList)ViewBag.Roles, new { @class = "dropdown-menu animated flipInX", @tabindex = "13" })
              &lt;/button&gt;
                  @Html.ValidationMessageFor(model =&gt; model.RoleID, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Have I missed something blindingly obvious or made a simple mistake? I'm pretty new to MVC/Razor.</p>
  
  <p>Here's how they look on the page:</p>
  
  <p><a href="https://i.stack.imgur.com/mkKd9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mkKd9.png" alt="enter image description here"></a></p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>The third one renders as this:</p>
  
  <pre><code>    &lt;div class="form-group"&gt;
              &lt;label class="control-label col-md-2" for="RoleID"&gt;User Level&lt;/label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;div class="btn-group m-b-5"&gt;
                      &lt;button type="button" class="btn btn-sm dropdown-toggle" data-toggle="dropdown"&gt;Please select a user level
                          &lt;select class="dropdown-menu animated flipInX" id="RoleID" name="RoleID" tabindex="13"&gt;&lt;option value="1"&gt;Internal&lt;/option&gt;
  &lt;option value="2"&gt;External&lt;/option&gt;
  &lt;option value="3"&gt;Administrator&lt;/option&gt;
  &lt;/select&gt;
                      &lt;/button&gt;
                          &lt;span class="field-validation-valid text-danger" data-valmsg-for="RoleID" data-valmsg-replace="true"&gt;&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>