title: How to display pdf in a iframe from a byte array c# MVC .NET Core
body: <p>I have searched the web for an answer but without any luck. I'm wondering how and if I'm able to render a pdf-file using Razor into a iFrame located in my view. The pdf is a byte array and is loaded in my Model.</p>
  
  <p>This is my code so far:</p>
  
  <pre><code>public ActionResult ByteConverter(byte[] pdfData)
  {
      MemoryStream Stream = new MemoryStream(pdfData);
      Stream.Write(pdfData, 0 , pdfData.Length);
      Stream.Position = 0;
      return new FileStreamResult(Stream,"application/pdf");
  }
  </code></pre>
  
  <p>My Model:</p>
  
  <pre><code> public async Task&lt;ActionResult&gt; Index()
   {
       ApiClient api = new ApiClient("http://localhost:43674/ApiCore");
       var result = await api.GetAsync();
  
         RegulationViewModel viewModel = new RegulationViewModel
         {
           ConnectedToRoadMap = result.ConnectedToRoadMap,
           Decided = result.Decided,
           Enforced = result.Enforced,
           Id = result.Id,
           Paragraph = result.Paragraph,
           Pdf = result.Pdf,
           Published = result.Published,
           Region = result.Region,
           StructuredInfo = result.StructuredInfo,
           Title = result.Title,
           ValidThru = result.ValidThru  
          };
  
          ByteConverter(viewModel.Pdf);
  
          return View(viewModel);
  }
  </code></pre>
  
  <p>And my view: </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class="tab-pane active" id="dokument"&gt;
      &lt;iframe src="@Url.Action("ByteConverter", "RegulationController")"&gt;&lt;/iframe&gt;
  &lt;/div&gt;
  </code></pre>