title: Returning ValidationSummary in Partial View to Ajax error handler - nothing else getting rendered
body: <p>I'm calling a method from Ajax that updates a some content in the page by loading up a partial view &amp; setting a contained property appropriately.</p>
  
  <p>This all works ok but I'm having problems with server side validation using the ValidationSummary control.  I'm using an approach suggested elsewhere to stick the ValidationSummary in a partial view.  (I've actually got client side validation turned off &amp; I'm trying to get server side validation to work using the same validation summary that client side validation uses)</p>
  
  <p>When there is a validation error, ajax error handler should update the contents of a div with the partial view that is returned.</p>
  
  <p>All this works ok in the sense that the validation summary is rendered with the expected error messages except for the fact that the nothing else is getting displayed on the page other than the partial view containing the validation summary and its containing elements.  i.e. no siblings / of the div are getting rendered</p>
  
  <p>I reaslly haven't got a clue what's going on.  Intersetingly, if I comment out the line in the error handler that updates the div with the partial, I see the form in its entirety again.</p>
  
  <p>I'm using an ExceptionFilter:</p>
  
  <pre><code>public class ValidationErrorAttribute : FilterAttribute, IExceptionFilter
  {
  public virtual void OnException(ExceptionContext filterContext)
  {
      if (filterContext == null)
      {
          throw new ArgumentNullException("filterContext");
      }
  
      if (filterContext.Exception != null)
      {
          filterContext.ExceptionHandled = true;
          filterContext.HttpContext.Response.Clear();
          filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
          filterContext.HttpContext.Response.StatusCode =  
          (int)System.Net.HttpStatusCode.BadRequest;
          //return the partial view containing the validationsummary and set the ViewData
          //so that it displays the validation error messages
          filterContext.Result = new PartialViewResult { ViewName = "validation",   
          ViewData = filterContext.Controller.ViewData  };
      }
  }
  }
  </code></pre>
  
  <p>when there's a validation error, throw a validationexception which will 
  trigger the OnException method of the filter          </p>
  
  <pre><code>    //Controller
      [HttpPost]
      [ValidationErrorAttribute]
      public ActionResult Save(ConsumptionData consumptionData)
      {
          if (ModelState.IsValid)
          {
              var dto = Mapper.Map&lt;ConsumptionData, ConsumptionDataDto&gt;(consumptionData);
              var refId = _personalProjectionRepository.AddPersonalProjectionRecord(dto);
              consumptionData.ReferenceId = refId;
              return PartialView("Reference", consumptionData);
          }
          else
          {
              throw new ValidationException();
          }   
      }
  </code></pre>
  
  <p>The validation partial view:</p>
  
  <pre><code>       @model PersonalProjection.Web.Models.ConsumptionData
         @Html.ValidationSummary()
  </code></pre>
  
  <p>and the jquery:</p>
  
  <pre><code>        $('form').submit(function () {
          var form = $(this);
          if (form.valid())
          {
  
              $.ajax({
                  url: form.attr("action"),
                  type: "POST",
                  dataType: "html",
                  contentType: "application/json; charset=utf-8",
                  data: JSON.stringify({
                      SiteId: $('#siteid').val(),
                      ElectricityConsumption: $('#electricityconsumption').val(),
                      ElectricitySpend: $('#electricityspend').val(),
                      GasConsumption: $('#gasconsumption').val(),
                      GasSpend: $('#gasspend').val()
                  }),
                  success: function (result) {
                      $('#rightPanelSection').html(result);
                  },
                  error: function (jqXHR) {
                      $('#validationSummary').html(jqXHR.responseText);
                  }
  
              });
          }
          return false;
      });
  </code></pre>
  
  <p>and the index.cshtml markup</p>
  
  <pre><code> &lt;div class="panel panel-outcome"&gt;
  
  
   @using (Html.BeginForm("Save", "Home", FormMethod.Post, (object)new { ID  =  
   "projectionForm" }))
  
  {
  &lt;div id="validationSummary"/&gt;
  
  &lt;div id="topPanelSection" class="panel-section"&gt;
      @Html.LabelFor(m =&gt; m.SiteId, new { id = "siteidlabel" })
      @Html.TextBoxFor(m =&gt; m.SiteId, ViewBag.TextBoxDisabled ? (object)new { id = 
      "siteid", disabled = true, maxlength = 9, @class = "input-disabled", @Value = 
      ViewBag.SiteId } : new { id = "siteid", maxlength = 9 })
      &lt;span id="errorText" class="error-text" /&gt;
  &lt;/div&gt;
  &lt;div id="leftPanelSection" class="panel-section"&gt;
      &lt;div class="column-heading"&gt;
          &lt;span class="column-heading-left"&gt;Total Cost&lt;/span&gt;
          &lt;span class="column-heading-right"&gt;Total Consumption&lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="panel-section-row"&gt; 
          @Html.LabelFor(m =&gt; m.ElectricitySpend, new { id = "electricitylabel" })   
          &lt;span&gt;£&lt;/span&gt;  
           @Html.TextBoxFor(m =&gt; m.ElectricitySpend, new { @class = "textbox-right-
           margin", id = "electricityspend" })  
           @Html.TextBoxFor(m =&gt; m.ElectricityConsumption, new { @class = "textbox-
           left-margin", id = "electricityconsumption" }) 
          &lt;span&gt;kWhs&lt;/span&gt;
      &lt;/div&gt; 
      &lt;div class="panel-section-row"&gt;
          @Html.LabelFor(m =&gt; m.GasSpend, new { id = "gaslabel" })   
          &lt;span&gt;£&lt;/span&gt;  
           @Html.TextBoxFor(m =&gt; m.GasSpend, new { @class = "textbox-right-margin", id = 
           "gasspend" })  
           @Html.TextBoxFor(m =&gt; m.GasConsumption, new { @class = "textbox-left-margin",
           id = "gasconsumption" }) 
          &lt;span&gt;kWhs&lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="panel-section-row"&gt;
          &lt;button type="reset" id="resetbutton"&gt;Reset Form&lt;/button&gt;
          &lt;button type="submit"&gt;Generate Reference Id&lt;/button&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="rightPanelSection" class="panel-section"&gt;
      @Html.Partial("Reference", Model)
  &lt;/div&gt;
  </code></pre>
  
  <p>}
  </p>