title: Display pdf created on the fly on modal dialog
body: <p>*Summary in the end.</p>
  
  <p>I read many many questions like mine here on SO and other sites to try and solve my problem, but I couldn't find the solution to the final bit of the problem.</p>
  
  <p><strong>DESCRIPTION:</strong></p>
  
  <p>I have a table (jqGrid) where I display some data from a database, like this:</p>
  
  <pre><code>+------+-----+
  | Name | Age |
  +------------+
  | test |  1  |
  +------+-----+
  </code></pre>
  
  <p>and I have a button that generates a PDF with information of the currently select row.</p>
  
  <p>To accomplish this, when the user clicks on the button "PDF" I create a form with hidden inputs and set their values:</p>
  
  <pre><code>//create a form
  $("&lt;form&gt;").attr({
     "id" : "invform",
     "method" : "post",
     "action" : "Home/generatePdf"
   });
  </code></pre>
  
  <p>Then I create the inputs and hide them and submit the form to the server...</p>
  
  <pre><code>//Id of selected row
  var selectedRowId = $("#grid").jqGrid('getGridParam', 'selrow');
  //Value of column Name of selected row
  var cellValue = $("#grid").jqGrid('getCell', selectedRowId, 'name');
  
  $("#invform")
  .append($("&lt;input&gt;").attr({"name" : "Name", "type" : "text", "value" : cellValue}))
  
  //hide all inputs
  $("#invform input").attr({"hidden" : "true"});
  
  //submit form
  $("#invform").submit();
  </code></pre>
  
  <p>The form is then sent to my controller and populates the obj with all the data:</p>
  
  <pre><code>public FileStreamResult generatePdf(Model obj)
  {
   PDF myPdf = &lt;code for generating the pdf&gt;;
  
   byte[] byteArr = myPdf.toByteArray();
  
   MemoryStream ms = new MemoryStream();
   ms.Write(byteArr, 0, byteArr.Length);
  
   HttpContext.Response.AddHeader("content-disposition",
   "inline; filename=" + randomName + ".pdf"); //random name is just a string based on time etc
  
   return new FileStreamResult(ms, "application/pdf");
  }
  </code></pre>
  
  <p>All this is working perfectly.</p>
  
  <p><strong>PROBLEM:</strong></p>
  
  <p>After I call submit() on the form, the controllers is called and the pdf is returned and displayed on the same tab. I need this form to be displayed on a modal window I have.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div id="pdfdiv" style="display:none"&gt;
      &lt;iframe id="pdfframe" style="width:100%; height:100%;"&gt;
      &lt;/iframe&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>$("#pdfdiv").dialog({
    height: ($(window).height() * 0.95),
    width: ($(window).width() * 0.45),
    position: {
      my: "center bottom",
      at: "center top",
      of: $(window)
    }
  });
  </code></pre>
  
  <p>I don't know what to put on the "src" attribute of the iframe to make the pdf be displayed there and not on the sabe browser tab.
  I feel like this is something easy to do and Im missing something because Im new to web development.</p>
  
  <p>Summary: my pdf returned from the controller is being displayed on the same browser tab, I need to make it appear on a jquery dialog, but I dont know what to put in the iframe src attribute because the pdf is generated after a form is submitted.</p>