title: Handling different partial views returning from the same MVC methjod via jQuery Ajax
body: <p>Setup:
  ASP.NET MVC3, jQuery, C#</p>
  
  <p>Has anyone got a clean solution to handle different partial views returning from the same action method? One for the next stage, one for returning the view again with validation errors and the other for display an unhandled exception.</p>
  
  <p>I have a <strong>controller method</strong> that does something like:</p>
  
  <pre><code>public ActionResult SomeMethod(MyModel model)
  {
  
      if(_service.Validate(model))
      {
  
      if(_service.Update(model))
      {
          // return next view once success
                  return PartialView("EverythingIsGood"); // This should be pushed into #somediv  
      }else{
          throw new HardException("Tell the client something bad has happened");
      }
      }
      else
      {
      // Return the same view to highlight the validation errors
          HttpContext.Response.StatusCode = 500;
      return PartialView("SomeMethod", model); // This should be pushed into #anotherdiv  
      }
  
  }
  </code></pre>
  
  <p><strong>Client Script</strong></p>
  
  <pre><code> $.ajax({
          url: baseUrl + "Home/SomeMethod",
          type: "GET",
          success: function (data) {
              $("#somediv").html(data);
          },
          error: function (data) {
              handleError(data);
          }
      });
  </code></pre>
  
  <p>I guessing I need something like <strong>softerror</strong>:</p>
  
  <pre><code>  $.ajax({
          url: baseUrl + "Home/SomeMethod",
          type: "GET",
          success: function (data) {
              $("#somediv").html(data);
          },
          softerror: function (data) {
              $("#anotherdiv").html(data);
          },
          error: function (data) {
              handleError(data);
          }
      });
  </code></pre>
  
  <p>I was thinking of maybe returning a different status code for the soft validation errors but this feels hacky.</p>