title: Client side validation not working
body: <p>I implemented client side validation i.e, Required <code>attributes</code> specified in <code>Model</code> and <code>HTML</code>.<code>ValidationMesssage</code> For in <code>.cshtml</code> and referenced the <code>JQuery</code> validator and was working fine when I click on <code>save button</code>. But when I implement <code>onClick event</code> of button an ajax call, the validation seems to be not working. I tried using <code>IsValid</code> but no luck. </p>
  
  <p>Please find the below code.</p>
  
  <p>Controller</p>
  
  <pre><code>  [HttpPost]
          public ActionResult AddClient(ClientModel clientData)
          {
              var clientObj = new Metadata.Client.Service.Client();
  
              string successMessage = string.Empty;
  
              clientObj.ClientType              = new Metadata.Client.Service.ClientType();
              clientObj.ClientName              = clientData.Client.ClientName;
              clientObj.ClientCode              = clientData.Client.ClientCode;
              clientObj.ClientType.ClientTypeId = clientData.ClientTypeSelectId;
  
               try
               {
                   clientObj = clientData.AddNewClient(clientObj);
               }
               catch (Exception ex)
               {
  
                    return new ContentResult { Content = ex.Message, ContentType = "application/json" };
  
               }
  
               return new ContentResult { Content = successMessage, ContentType = "application/json" };
               //return RedirectToAction("Index");
  
          }
  </code></pre>
  
  <h2>JQuery - Added the below references.</h2>
  
  <pre><code>&lt;script src="../../Scripts/jquery.validate.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="../../Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js" type="text/javascript"&gt;&lt;/script&gt;
   $("#addForm").validate(
      {
  
  
          submitHandler: function (form) 
          {
                  var clientName = $('#Client_ClientName').val();
                  var clientTypeId = $('#ClientTypeSelectId').val();
                  var clientCode = $('#Client_ClientCode').val();
  
             $.ajax({
                      type: "POST",
                      async: false,
                      url: "/Client/AddClient",
                      cache: false,
                      data: { "clientName": clientName, "clientTypeId": clientTypeId, "clientCode": clientCode },
                      dataType: "json",
                      error: function (request) {
                          alert(request.responseText);
                      },
                      success: function (result) {
                          //alert('Successfully Inserted Client');
                          $.ajax({
                              url: "/Client/ClientGrid",
                              type: 'GET',
                              datatype: 'json',
                              success: function (data) {
                                  $('#grid').html(data);
                                  //alert('got here with data');
                              },
                              error: function () {
                                  //alert('something bad happened');
                              }
                          });
  
                          $('#myClientDialogContainer').dialog('close');
                      }
                  });
                  return false;
              }
          });
  </code></pre>
  
  <h1>Model</h1>
  
  <pre><code>   public class Client
      {
          public int ClientId { get; set; }
  
          [Required(ErrorMessage = "Please Enter Client Name")]
          [Display(Name = "Client Name")]
          public string ClientName { get; set; }
  
          public ClientType ClientType { get; set; }
          public StatusType StatusType { get; set; }
  
          //[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
          [Required(ErrorMessage = "Please Enter Client Code")]
          [DataType(DataType.Text)]
          [Display(Name = "Client Code")]
          public string ClientCode { get; set; }
  
          //[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
          [DataType(DataType.Text)]
          [Display(Name = "Client Status Type Name")]
          public string ClientStatusTypeName { get; set; }
  
          //[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
          [DataType(DataType.Text)]
          [Display(Name = "Client Status Code Name")]
          public string ClientStatusCodeName { get; set; }
  
          [Display(Name = "Client Type Id")]
          public int ClientTypeId { get; set; }
      }
  </code></pre>
  
  <h1>Validation code</h1>
  
  <pre><code>&lt;div class="editor-field"&gt;
      &lt;span&gt;
  
          @Html.ValidationMessageFor(c =&gt; c.Client.ClientName)
          &lt;div class="row"&gt;&lt;/div&gt;
          &lt;span class ="label"&gt; @Html.LabelFor(c =&gt; c.Client.ClientName, "Client Name :")&lt;/span&gt;
          @Html.TextBoxFor(c =&gt; c.Client.ClientName, new { style = "width:50%; height:20px;" })
      &lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;span&gt;
               @Html.ValidationMessageFor(m =&gt; m.ClientTypeSelectId)
               &lt;div class="row"&gt;&lt;/div&gt;
              &lt;span class ="label"&gt;@Html.LabelFor(m =&gt; Model.Client.ClientType.ClientTypeName, "Client Type :")&lt;/span&gt;
               @Html.DropDownListFor(m =&gt; m.ClientTypeSelectId, (SelectList)ViewBag.clientTypeListCombo, " ", new { style = "width:52%" })
  
  
          &lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="editor-label"&gt;
          &lt;span&gt;
              @Html.ValidationMessageFor(m =&gt; m.Client.ClientCode)
              &lt;div class="row"&gt;&lt;/div&gt;
              &lt;span class="label"&gt;@Html.LabelFor(m =&gt; m.Client.ClientCode, "Client Code :")&lt;/span&gt;
              @Html.TextBoxFor(m =&gt; m.Client.ClientCode, new { style = "width:50%; height:20px;" })
          &lt;/span&gt; 
      &lt;/div&gt;
  </code></pre>
  
  <p>Please can anyone help.</p>