title: MVC5 - Data Annotations - Client Side Validation Not Happening?
body: <p>I have an MVC 5 app, and I'm using data annotations to do a majority of validation. One of the properties in my class looks like this:</p>
  
  <pre><code>[Required(ErrorMessage = "Please enter a business name")]
  [StringLength(80)]
  public string BusinessName { get; set; }
  </code></pre>
  
  <p>The validation is working but it doesn't appear to be happening in the browser like I thought it should. On my page I have a Save button. If I leave the Business Name field blank and click Save, a post is done to a controller method that looks, partially, as follows:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Create(Advertiser advertiser, FormCollection collection, HttpPostedFileBase file)
      {
          // Before we do anything, let's check to make sure any validation that's already been done is clean.
          if (!ModelState.IsValid)
          {
              return View(advertiser);
          }
     ...
     ...
  }
  </code></pre>
  
  <p>When this method is executed, the model state is already set to invalid. That's good because it is invalid because the Business Name field is empty. However, shouldn't this validation be happening in the client?</p>
  
  <p>The field in my .cshtml file looks as follows (using Bootstrap):</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      @Html.Label("Business Name", new { @class = "control-label col-md-3" })
      &lt;div class="col-md-9"&gt;
          @Html.TextBoxFor(model =&gt; model.BusinessName, new { @class = "form-control", title = "", autofocus = true })
          @Html.ValidationMessageFor(model =&gt; model.BusinessName)
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My Web.Config is set correctly as follows:</p>
  
  <pre><code>&lt;appSettings&gt;
      &lt;add key="webpages:Version" value="3.0.0.0" /&gt;
      &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;add key="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
    &lt;/appSettings&gt;
  </code></pre>