title: ASP.NET MVC rendering partial view with jQuery ajax
body: <p>I have a controller action which renders a partial view:</p>
  
  <pre><code>public ActionResult Details(int id)
  {
      DetailsViewModel model = 
          ModelBuilder.GetDetailsViewModel(id, _repository);
      return PartialView("Details", model);
  }
  </code></pre>
  
  <p>and I'm loading the returned content into a dynamic element as follows:</p>
  
  <pre><code>$container = appendContainer(); // adds a div to the dom with the correct id
  $container.load("MyController/Details", function(response, status, xhr) {
      if (status != "success") {
          $(container).html('an error has occured');
      }
  });
  </code></pre>
  
  <p>so this creates a div, and then loads the returned content into that div.</p>
  
  <p>I want to alter this slightly so that the container div is only created if the call
  to the controller is succesful.</p>
  
  <p>So:</p>
  
  <ol>
  <li>jQuery calls the controller action</li>
  <li>controller returns PartialView, or null if Id not found</li>
  <li>If PartialView is returned, the container is created and loaded with the returned content. </li>
  <li>If the controller doesn't find the Id, no content is created and an alert is displayed.</li>
  </ol>
  
  <p>I'd appreciate any pointers on how I could best acheive this. </p>