title: Validation for @Html.DropDownList and @Html.DropDownListFor in Razor using C# asp.net mvc code first approach
body: <p>I am very new in MVC and my previous experience was asp.net web forms, now i am getting difficulty to add Validation for @Html.DropDownList and  @Html.DropDownListFor in Razor using C# asp.net mvc code first approach</p>
  
  <p>Below is my design:</p>
  
  <pre><code>   &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.State, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownList("States", new SelectList(ViewBag.States as System.Collections.IEnumerable, "StateId", "StateName", new { @class = "control-label col-md-2" }), "Select a State", new { id = "dd_State" })
  
          &lt;/div&gt;
      &lt;/div&gt;
  
        &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.City, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownListFor(Model =&gt; Model.City, new SelectList(Enumerable.Empty&lt;SelectListItem&gt;(), "CityName", "CityName"),"Select a City", new { id = "dd_City" })
              &lt;span id="span1" name="span1"&gt;&lt;/span&gt;
            &lt;/div&gt;
        &lt;/div&gt;
  </code></pre>
  
  <p>Below is my Models code Register.cs and not able to add require fields of <strong>State</strong> and <strong>City</strong></p>
  
  <pre><code>  [Table("Register")]
  public class Register
  {
      [Key]
      public int Sno { get; set; }
      [Required(ErrorMessage = "Name is required.")]
      [Display(Name = "Full name")]
      public string Fullname { get; set; }
      [Display(Name = "Email Id")]
      [Required(ErrorMessage = "Email is required.")]
      public string EmailId { get; set; }
      [Required(ErrorMessage = "Password is required.")]
      public string Password { get; set; }
      [Required(ErrorMessage = "Mobile is required.")]
      public string Mobile { get; set; }
      [Required(ErrorMessage = "Address is required.")]
      public string Address { get; set; }
      public string State { get; set; }
      public string City { get; set; }
      [Required(ErrorMessage = "Entity is required.")]
      public string EntityType { get; set; }
      public string Website { get; set; }
      public string PinCode { get; set; }
      public string accountactivated { get; set; }
  
  }
  </code></pre>
  
  <p>Also i am not able to add bootstrap css to @Html.DropDownList and @Html.DropDownListFor please check dropdown look.</p>
  
  <p><a href="https://i.stack.imgur.com/X6r60.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>My State and city model class.</p>
  
  <p><a href="https://i.stack.imgur.com/jjPuA.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p><a href="https://i.stack.imgur.com/f4DG5.png" rel="nofollow noreferrer">enter image description here</a></p>