title: ASP.NET MVC: How to validate an Ajax form with a specified UpdateTargetID?
body: <p>I'm trying to figure out how to show validation errors after a user submits an Ajax form that has its <code>UpdateTargetID</code> property set.</p>
  
  <p>I'm stumped on how to update the Ajax form with the validation errors without returning the <code>Create</code> PartialView into the <code>results</code> div. If the form is valid, then it should return the <code>Records</code> PartialView.</p>
  
  <p><strong>Create.ascx</strong></p>
  
  <pre><code>&lt;%  Using Ajax.BeginForm("Create", 
                           "Record", 
                           New Record With {.UserID = Model.UserID}, 
                           New AjaxOptions With {
                               .UpdateTargetId = "results", 
                               .LoadingElementId = "loader"
                           })%&gt;        
      Date Located
      &lt;%= Html.TextBoxFor(Function(model) model.DateLocated)%&gt;
      &lt;%= Html.ValidationMessageFor(Function(model) model.DateLocated) %&gt;
  
      Description
      &lt;%= Html.TextBoxFor(Function(model) model.Description)%&gt;
      &lt;%= Html.ValidationMessageFor(Function(model) model.Description) %&gt;
  
      &lt;input id="btnSave" type="submit" value="Create" /&gt;          
  
      &lt;span id="loader" class="loader"&gt;Saving...&lt;/span&gt;
  &lt;%End Using%&gt;
  </code></pre>
  
  <p><strong>Records.ascx</strong></p>
  
  <pre><code>&lt;div id="results"&gt;
      ...
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>RecordController.vb</strong></p>
  
  <pre><code>Function Create(ByVal newRecord As Record) As ActionResult
      ValidateRecord(newRecord)
  
      If Not ModelState.IsValid Then
          Return PartialView("Create", newRecord)
      End If
  
      _repository.Add(newRecord)
      _repository.Save()
  
      Dim user = _repository.GetUser(newRecord.UserID)
      Return PartialView("Records", user)
  End Function
  </code></pre>