title: MVC And Ajax.BeginForm and DIV.Load
body: <p>I have a partial that defines an Ajax.BeginForm. The model returned has a property for ReportLink created on the server resource that returns a Url to a PartialView.</p>
  
  <p>On the Ajax,BeginForm.OnSuccessFunction I am attempting to return and load html content with <code>$("reportContent").load(AJAXRESULT.RenderLink)</code></p>
  
  <p>However, I get into an infinite loop somewhere.</p>
  
  <p>Edited to add moving parts:</p>
  
  <pre><code>@model xxxx.Reports.Models.Reports.BaseReportModel
  @{Layout = null;}
  &lt;div id="reportBase" class="k-content"&gt;
  &lt;div id="reportControl" &gt;  
  @using (Ajax.BeginForm(
            Model.PostAction,          
            Model.PostController,
            null,
            new AjaxOptions() { OnSuccess = "editPostSuccess", OnFailure = "editPostFailure" },
            new { id = "reportBase_frmViewer", name = "reportBase_frmViewer" }))
          {    
              @Html.AntiForgeryToken()            
              @RenderSection("reportParams", required: false)  
              if (@Model.AllowRefresh){
                  &lt;input type="button" id="btnRefresh" value="refresh" /&gt;
              }
              if (@Model.AllowExportToPDF){
                  &lt;input type="button" id="btnPDF" value="PDF" /&gt;
              }
              if (@Model.AllowExportToExcel){
                  &lt;input type="button" id="btnExcel" value="XLS" /&gt;
              }  
              @Html.HiddenFor(p =&gt; p.AllowExportToExcel)   
              @Html.HiddenFor(p =&gt; p.AllowExportToPDF)
              @Html.HiddenFor(p =&gt; p.AllowRefresh)      
              @Html.HiddenFor(p =&gt; p.AutoStartReport)   
          }   
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="wait"&gt;&lt;/div&gt;
  &lt;div id="reportContent"&gt;&lt;/div&gt;
  //The 
  &lt;script type="text/javascript"&gt;
  
      function editPostSuccess(ajaxContext) {
          showWaitIndicator(false);       
          $('#reportContent').load(ajaxContext.RenderLink**,&lt;--This is a link to an asction that calls renderPartial on the controller** function () {
              $("#reportContent").show();
          });
      }
  
      function editPostFailure(ajaxContext) {
          showWaitIndicator(false);
          var response = JSON.parse(ajaxContext.responseText);
          var errorMessage = response.Message;
          $('#reportContent').html('@Resources.labels.lblServerErrorsOnForm' + " " + errorMessage);
          $("#reportContent").show();
          alert("FAILURE:"+response.Message);
      }
  </code></pre>
  
  <p><strong>Update:</strong> I am no longer sure that browser is locking up. The content is 3.15 MB. I think the raw html is very verbose and takes that long to render in the browser. Here is the execution sequence:</p>
  
  <ol>
  <li><p>LoadPartial(ReportModel) - This has an Ajax.BeginForm() that returns report meta data and has a refresh button. When the refresh button is clicked. I call a js function that loads a div using div.load(ReportModel.RenderLink), which is a url to get the content as html from the controller.</p></li>
  <li><p>The ReportModel.RenderLink points to a controller method that returns an html report based on model params sent to the controller. The result is a PartialView("ReportContentPartial",string) where string is the html fragment.</p></li>
  <li><p>For testing the ReportContentPartial just dumps @Model into a div as @Html.Raw(Model) and this is where the browser locks up. I thought it was in an infinite loop but it is just taking way to long to render the html.</p></li>
  </ol>
  
  <p>The part I do not understand is when I use @Html.BeginForm and dump the @Html.Raw(HTML) it is pretty quick. I need to somehow use the same mechanism used in that rendering method. The report html is fetched and returned in less than a second. The problem is when I trace out of @Html.Raw(HTML) the browser locks and takes +15 seconds to render the content.</p>
  
  <p>I will keep plugging at it. I am sure there is a more efficient way to go about it and I probably need to think about ways to break up the reports.</p>
  
  <p><strong>Update 2:</strong> This seems to be development environment issue. I am launching IE from VS2012 using the run command. I sense that something is up with the asp.net dev  server. When I load the same url in chrome, while debugging in vs, it renders in less than a second.</p>