title: Send exception message in Ajax.BeginForm MVC 4 scenario
body: <p>I have a partial view that contains an ajax form. The view simply adds and updates user information.</p>
  
  <p>The controller sends the same partial view back as ActionResult. </p>
  
  <p>What I want to do is to display an error message if the transaction was not successful. But it should still send back the partial view, only this time with a message.</p>
  
  <p>How would this be achieved?</p>
  
  <p>Code:</p>
  
  <p><strong>ManageUsers.cshtml</strong></p>
  
  <pre><code>&lt;div id="details"&gt;
  @{
      Html.RenderPartial("AddModifyUserPartialView");
  }
  &lt;/div&gt;
  
  @{
      Html.RenderPartial("ListUsersPartialView");
   }
  </code></pre>
  
  <p><strong>AddModifyUserPartialView.cshtml</strong></p>
  
  <pre><code>@using (Ajax.BeginForm("AddModifyUser", "Account", FormMethod.Post, 
           new AjaxOptions() 
           { 
               UpdateTargetId = "details", 
               OnFailure= "handleError", 
               OnSuccess="handleSuccess" 
           }, 
           new { id = "useragentform", 
                 enctype = "multipart/form-data" }))
  {
    //form fields here
    &lt;input type="submit" id="savebutton" name="savebutton" value="Add New User" /&gt;
  }
  </code></pre>
  
  <p>Also in the partial view:</p>
  
  <pre><code>function handleError(ajaxContext) {
  
      var response = ajaxContext.get_response();
      var statusCode = response.get_statusCode();
  
      alert(statusCode);
  }
  </code></pre>
  
  <p><strong>Account Controller</strong></p>
  
  <pre><code>try
  {
       SecurityManager.AddUpdateUserAgent(ua);
  }
  catch (Exception ex)
  {
       //how do I send the message back along with the partial view???
  }
  return PartialView("AddModifyUserPartialView");
  </code></pre>