title: Validation in Partial View not working in MVC 4
body: <p>I have a  <code>@Html.ValidationMessageFor(model =&gt; model.FirstName)</code> in Partial view that is not functioning properly. The text box's contained within the loaded Partial View have the "Required" Data Annotation on them and the associated message displays right away. How can I avoid this? It doesn't even validate.</p>
  
  <p>Partial View Code</p>
  
  <pre><code>@{ Html.EnableClientValidation(); }
  @*@{ ViewContext.FormContext = new FormContext(); }*@
  @using (Html.BeginForm("ActionName", "ControllerName"))
  {
  
  &lt;div&gt;
      @Html.TextBoxFor(model =&gt; model.FirstName)
      @Html.ValidationMessageFor(model =&gt; model.FirstName)
  &lt;/div&gt;
  ....//some more HTML
  }
  </code></pre>
  
  <p>Main View Code</p>
  
  <pre><code>&lt;div class="modal" id="modalId" role="dialog"&gt;
      &lt;div class="modal-dialog"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
  
              &lt;/div&gt;
              &lt;div class="modal-body" id="modalbodyId"&gt;
                  @Html.Partial("PartilViewName")
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have tried the following things so far.<br>
  1. Added the following line of code in Partial View   </p>
  
  <pre><code>@{ ViewContext.FormContext = new FormContext(); }    
  </code></pre>
  
  <p>2.Both <code>ClientValidationEnabled</code> and <code>UnobtrusiveJavaScriptEnabled</code> are set to <code>true</code> in <code>web.config</code>     </p>
  
  <p>3.Added the following <code>script</code> tags in <code>BundleConfig.cs</code></p>
  
  <pre><code>&lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <blockquote>
    <p>In all the posts that I have seen I need to use an AJAX call like the below code.
    However I am not sure on how to use it.</p>
  </blockquote>
  
  <pre><code> $("#create").click(function () {
              var form = $("#create_person").closest("form");
              form.removeData('validator');
              form.removeData('unobtrusiveValidation');
              $.validator.unobtrusive.parse(form);
  
              $.ajax({
                  url: "/Person/CreateOrUpdate",
                  type: "POST",
                  data: $("#create_person").serialize(),
                  cache: false
              });
  
  
          });
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/16031800/mvc-4-validation-with-a-partial-view">Code Courtsey</a></p>