title: MVC Ajax.BeginForm OnSuccess function not defined
body: <p>I'm trying to get my Ajax.BeginForm to run a function OnSuccess but I keep getting in firebug the error message:</p>
  
  <pre><code>UpdateProjectDiv is not defined
   return Function.constructor.apply(null, argNames); 
  </code></pre>
  
  <p>Here's what the form looks like:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function () {
  
          function UpdateProjectDiv() {
              var projid = $("#ddlProjectsManage").val();
  
              $.post("/Manage/ProjectEmployeeList/", { projectid: projid }, function (data) {
                  populateDiv($("#divProjectsToFill"), data);
              });
          }
  
          function populateDiv(div, data) {
              div.html('');
              div.append(data);
          }
  
      });
  &lt;/script&gt;
  
  @using (Ajax.BeginForm("MoveToProject", new AjaxOptions { UpdateTargetId = "divAllEmployeesToFill", OnSuccess = "UpdateProjectDiv" }))
  {
      [insert non-relevant code here] 
  
      &lt;input id="btnMoveEmpsToProject" type="submit" value="&gt;&gt;"  /&gt;
      @Html.Hidden("SelectedProjectID","9999999999999")
  }
  </code></pre>
  
  <p>And My controller action:</p>
  
  <pre><code>[HttpPost]
  public ActionResult MoveToProject(UnassignedEmployeeBindingModel model, int selectedprojectId)
  {
      var tempteam = _db.SpecTeams.SingleOrDefault(s =&gt; s.Name == "N/A" &amp;&amp; s.ProjectId == selectedprojectId);
  
      try
      {
          foreach (var employee in model.UnassignedEmployees)
          {
              var employeeObj = _db.Employees.SingleOrDefault(e =&gt; e.Id == employee.Employee.Id);
  
              if (employee.IsSelected)
              {
                  employeeObj.SpecTeamId = tempteam.Id;
                  _db.SaveChanges();
              }
          }
  
          return RedirectToAction("UnassignedEmployeeList");
      }
      catch (Exception)
      {
          return RedirectToAction("Index");
      }
  }
  </code></pre>
  
  <p>Without the OnSucess the code it works fine, except it doesn't refresh the div in another partial (#divProjectsToFill) automatically.</p>
  
  <p>Additionally it seems to be looking for the function UpdateProjectDiv in the jquery.unobtrusive-ajax.js file rather than on the page itself. I suppose I might be able to add my function in that file (although I haven't tried yet) but that does not sound like a proper solution.</p>
  
  <p>Thanks!</p>