title: Full postback on ajax.beginform in chrome and firefox
body: <p>Similar to <a href="https://stackoverflow.com/questions/5061063/mvc-3-ajax-beginform-does-a-full-post-back">MVC 3 - Ajax.BeginForm does a full post back</a>, but I've verified that a reference to jquery.unobtrusive-ajax.min.js does exist in my page.  Plus, it works great in IE 9, but in Firefox and Chrome, I get just the partial view as a full web page instead of replacing the div with the contents of that partial view.</p>
  
  <p>I'm still pretty new to MVC3, so I'm sure it's something simple.</p>
  
  <p>Synopsis:</p>
  
  <p>Within my page, there are several different .cshtml files which become visible as users click on links.  Within the EquipmentData.cshtml file, I have a dropdown which, on change, does an ajax postback to the controller to load an editor template into a div.  </p>
  
  <p>Within that editor template (StorageTankData.cshtml), there is a list of data and has a placeholder for a edit template for a single item (StorageTank.cshtml).  StorageTank.cshtml is initialized for inserting a new one (with an id of zero); when the user clicks one of the items in the data list, we call the controller again to get the StorageTank.cshtml partial view for that specific item and replace that html into the edit div.</p>
  
  <p>All of that works great.  In the StorageTank.cshtml template, I have an Ajax.Begin form which posts to a different controller action to save the storage tank data, and then calls the same controller method to get the StorageTankData.cshtml partial view.  The idea is that we'll refresh the list of items and reset the edit form to insert mode and replace that into the div.</p>
  
  <p>That works fine in IE, but in Chrome and Firefox I get just the partial view on the page instead of the whole page with the replacement happening.  I <em>think</em> it's because my save postback goes to a different controller method than the one which generates the entire page, but I'm not sure what to do about that.</p>
  
  <p>What I see in IE is that the URL stays on "/Edit" (the action which controls the whole page) and the substitution works great.  In Chrome and FF, the url changes to my "/SaveStorageTank" action instead.  So, I think that explains why those browser display just the partial view when done.  What I don't understand is why they don't go ahead and do the replace.</p>
  
  <p>I don't see errors in either Firebug or Chrome until after the re-display.  (Of course, they get tripped up on the $(document).ready... stuff, because that partial view does not have the jquery files loaded).  But, maybe I just don't know where/how to look for those errors.</p>
  
  <p>OK, sorry for the long story.  Here's some details.</p>
  
  <p><strong>EquipmentEdit.cshtml</strong></p>
  
  <pre><code>@model kpa.mko.bll.viewmodels.clientData.ClientDataFormViewModel
  
      &lt;table id="equipment"&gt;
          &lt;tr class="form-row"&gt;
              &lt;td class="form-left"&gt;Forklift On Site?&lt;/td&gt;
              &lt;td class="form-right"&gt;
                  @Html.EditorFor(x =&gt; x.ForkliftOnSite)
                  @Html.ValidationMessageFor(x =&gt; x.ForkliftOnSite)
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr class="form-row"&gt;
              &lt;td class="form-left"&gt;Equipment&lt;/td&gt;
              &lt;td class="form-right"&gt;
                  @Html.HiddenFor(m =&gt; m.AccountId)
                  Equipment Type: &lt;select id="ddlEquipmentType"&gt;
                      &lt;option value=""&gt;--select one--&lt;/option&gt;
                      @foreach (var lookupValue in Model.EquipmentTypes.OrderBy(lv =&gt; lv.ShortName))
                      {
                          &lt;option value="@lookupValue.LookupValueId"&gt;@lookupValue.ShortName&lt;/option&gt;
                      }
                  &lt;/select&gt;
                  &lt;div id="divEquipmentEdit" style="display: none;"&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              $("#ddlEquipmentType").change(
                  function () {
                      var selection = $("#ddlEquipmentType option:selected").text();
  
                      if (selection == "Storage Tanks") {
                          //Try to get the partial view of the editor template                }
                          $.ajax({
                              url: '@Url.Action("LoadStorageTankDataEditor")',
                              type: "POST",
                              contentType: "application/json; charset=utf-8",
                              data: JSON.stringify({ accountId: $('#AccountId').val() }),
                              dataType: "html",
                              success: function (view) {
                                  $('#divEquipmentEdit').show();
                                  $('#divEquipmentEdit').html(view);
                              },
                              error: function (xhr, ajaxOptions, thrownError) {
                                  alert('error = ' + thrownError);
                                  alert('xhr resp text = ' + xhr.responseText);
                              }
                          });
                      } else {
                          $('#divEquipmentEdit').hide();
                      }
                  }
              );
          });
      &lt;/script&gt;
  </code></pre>
  
  <p><strong>StorageTankData.cshtml</strong></p>
  
  <pre><code>@model kpa.mko.bll.viewmodels.clientData.StorageTankData
  
  @using kpa.mko.dal.Entities;
  
  Existing Tanks:
  &lt;br /&gt;&lt;br /&gt;
  @Html.HiddenFor(m =&gt; m.AccountId)
  @if (Model.StorageTanks.Count == 0)
  {
      &lt;div&gt;No tanks for this account.&lt;/div&gt;
  }
  else
  {
      foreach (StorageTank st in Model.StorageTanks)
      {
          @st.ListDescription &lt;a href="javascript:getEditor(@st.StorageTankID);"&gt;Edit&lt;/a&gt;&lt;br /&gt;
      }
  }
  
  &lt;br /&gt;&lt;br /&gt;
  &lt;div id="divTankEditor"&gt;
  &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          getEditor(0);
      });
  
      function getEditor(storageTankId) {
  
          //Substitute in the StorageTank editor to the div above.
          $.ajax({
              url: '@Url.Action("LoadStorageTankEditor")',
              type: "POST",
              contentType: "application/json; charset=utf-8",
              data: JSON.stringify({ storageTankId: storageTankId, accountId: $('#AccountId').val() }),
              dataType: "html",
              success: function (view) {
                  $('#divTankEditor').html(view);
                  if (storageTankId == 0) {
                      $('#btnTankDelete').hide();
                  } else {
                      $('#btnTankDelete').show();
                  }
              },
              error: function (xhr, ajaxOptions, thrownError) {
                  alert('error = ' + thrownError);
                  alert('xhr resp text = ' + xhr.responseText);
              }
          });
      }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>StorageTank.cshtml</strong></p>
  
  <pre><code>@model kpa.mko.bll.viewmodels.clientData.StorageTankForEdit
  
  @using kpa.mko.dal.Entities;
  @using kpa.mko.bll.factories;
  
  @using (Ajax.BeginForm("SaveStorageTank", "ClientData", new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "divEquipmentEdit" }))
  {
      @Html.HiddenFor(st =&gt; st.TankForEdit.StorageTankID)
      &lt;div&gt;Tank Placement:@Html.DropDownListFor(m =&gt; m.PlacementSelected, Model.Placements)&lt;/div&gt;
      &lt;div&gt;Department: @Html.DropDownListFor(m =&gt; m.DepartmentSelected, Model.Departments)&lt;/div&gt;
      &lt;div&gt;Volume (gal): @Html.EditorFor(m =&gt; m.TankForEdit.VolumeInGallons)&lt;/div&gt;
      &lt;div&gt;Content of Tank: @Html.DropDownListFor(m =&gt; m.StorageTankContentsSelected, Model.StorageTankContents)&lt;/div&gt;
      &lt;div&gt;Secondary Containment? @Html.EditorFor(m =&gt; m.TankForEdit.HasSecondaryContainment)&lt;/div&gt;
      &lt;div&gt;If so, what type: @Html.EditorFor(m =&gt; m.TankForEdit.SecondaryContainmentType)&lt;/div&gt;
      &lt;div&gt;Tank Has Overfill Alarm? @Html.EditorFor(m =&gt; m.TankForEdit.HasOverfillAlarm)&lt;/div&gt;
      &lt;div&gt;If so, what type: @Html.EditorFor(m =&gt; m.TankForEdit.OverfillAlarmType)&lt;/div&gt;
      &lt;input type="submit" value="Save Tank Data" name="submitButton" /&gt; &lt;input type="submit" value="Delete Tank" id="btnTankDelete" name="submitButton" /&gt; &lt;input type="button" value="Reset" onclick="getEditor(0); return false;" /&gt;
  }
  </code></pre>
  
  <p><strong>Controller method to save</strong></p>
  
  <pre><code>public PartialViewResult SaveStorageTank(string submitButton, string accountId)
  {
  int acctId = int.Parse(accountId);
  StorageTankForEdit stfe = new StorageTankForEdit(acctId);
  if (TryUpdateModel(stfe))
  {
      if (!string.IsNullOrEmpty(submitButton) &amp;&amp; submitButton.Equals("Delete Tank"))
      {
          //Delete the tank already.
          StorageTankFactory.Delete(stfe.TankForEdit);
      }
      else
      {
          stfe.TankForEdit.DepartmentFk = int.Parse(stfe.DepartmentSelected);
          stfe.TankForEdit.Placement = (StorageTankPlacement)Enum.Parse(typeof(StorageTankPlacement), stfe.PlacementSelected);
          stfe.TankForEdit.StorageTankContentFk = int.Parse(stfe.StorageTankContentsSelected);
          //@^*#$^ NHibernate doesn't bother to get the content class upon re-display, so we don't see the content type.
          //I think it's caching this tank, so let's try populating the content here and see if it shows up.
          stfe.TankForEdit.StorageTankContent = StorageTankContentFactory.GetById(stfe.TankForEdit.StorageTankContentFk);
          StorageTankFactory.Save(stfe.TankForEdit);
      }
  }
  
  //We decided to reset to the insert state.
  return LoadStorageTankDataEditor(acctId);
  </code></pre>
  
  <p><strong>Controller method to get StorageTankData partial view</strong></p>
  
  <pre><code>   public PartialViewResult LoadStorageTankDataEditor(int accountId)
      {
          StorageTankData std = new StorageTankData(accountId);
  
          std.StorageTanks = StorageTankFactory.GetByAccount(accountId);
  
          return PartialView("EditorTemplates/StorageTankData", std);
      }
  </code></pre>
  
  <p><strong>Controller method to get StorageTank partial view</strong></p>
  
  <pre><code>  public PartialViewResult LoadStorageTankEditor(int storageTankId, int accountId)
      {
          StorageTankForEdit st = new StorageTankForEdit(accountId);
          if (storageTankId &gt; 0)
          {
              st.TankForEdit = StorageTankFactory.GetById(storageTankId);
          }
          return PartialView("EditorTemplates/StorageTank", st);
      }
  </code></pre>