title: Validate Model data before ajax method call
body: <p>I have a partial view on my application I am creating user registration functionality on partial view(not using any form tag) , I am calling Controller's action method using ajax-jquery &amp; passing user details(model) to action method , before calling ajax method i need to validate user detail at client side. how can i do this?</p>
  
  <p>need to validate model before  ajax call(not using any form tag).</p>
  
  <pre><code>@model MVC4Demo.Models.Student
  
  &lt;script src="~/Scripts/jquery-1.7.1.min.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/jquery.validate.min.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/jquery.validate.unobtrusive.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  function onClientClick() {        
  
      var obj = { FirstName: "name",  City: "abc" };
      $.ajax({
          url: "/Home/AjaxDemo",
          data: JSON.stringify(obj),
          type: "POST",
          datatype: "json",
          contentType: "application/json; charset=utf-8",
          success: function (result) {
              alert('success');                
          },
          error: function () {
              alert("error");
          }
      });
  }
  &lt;/script&gt;
  
  
  &lt;div id="Main"&gt;
  &lt;label&gt;Student&lt;/label&gt;
  
  &lt;div class="editor-label"&gt;
      @Html.LabelFor(model =&gt; model.FirstName)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.EditorFor(model =&gt; model.FirstName)
      @Html.ValidationMessageFor(model =&gt; model.FirstName)
  &lt;/div&gt;
  
  &lt;div class="editor-label"&gt;
      @Html.LabelFor(model =&gt; model.LastName)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.EditorFor(model =&gt; model.LastName)
      @Html.ValidationMessageFor(model =&gt; model.LastName)
  &lt;/div&gt;
  
  &lt;div class="editor-label"&gt;
      @Html.LabelFor(model =&gt; model.City)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.EditorFor(model =&gt; model.City)
      @Html.ValidationMessageFor(model =&gt; model.City)
  &lt;/div&gt;
  
  &lt;p&gt;
      &lt;input type="submit" onclick="onClientClick()" value="Create" /&gt;
  &lt;/p&gt;
  &lt;/div&gt;
  
  
  &lt;div&gt;
  @Html.ActionLink("Back to List", "Index")
   &lt;/div&gt;
  </code></pre>