IRONSOFTWAREHOME
CSHTML to PDF (MVC Core)

// PM > Install-Package IronPdf.Extensions.Mvc.Core

public async Task<IActionResult> Persons()
{
    var persons = new List<Person>
    {
    new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
    new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
    new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
    };
    if (_httpContextAccessor.HttpContext.Request.Method == HttpMethod.Post.Method)
    {
        ChromePdfRenderer renderer = new ChromePdfRenderer();

        // Render View to PDF document
        PdfDocument pdf = renderer.RenderRazorViewToPdf(_viewRenderService, "Views/Home/Persons.cshtml", persons);
        Response.Headers.Add("Content-Disposition", "inline");

        // Output PDF document
        return File(pdf.BinaryData, "application/pdf", "viewToPdfMVCCore.pdf");
    }
    return View(persons);
}
Public Async Function Persons() As Task(Of IActionResult)
    Dim persons = New List(Of Person) From {
        New Person With {.Name = "Alice", .Title = "Mrs.", .Description = "Software Engineer"},
        New Person With {.Name = "Bob", .Title = "Mr.", .Description = "Software Engineer"},
        New Person With {.Name = "Charlie", .Title = "Mr.", .Description = "Software Engineer"}
    }

    If _httpContextAccessor.HttpContext.Request.Method = HttpMethod.Post.Method Then
        Dim renderer As New ChromePdfRenderer()

        ' Render View to PDF document
        Dim pdf As PdfDocument = renderer.RenderRazorViewToPdf(_viewRenderService, "Views/Home/Persons.cshtml", persons)
        Response.Headers.Add("Content-Disposition", "inline")

        ' Output PDF document
        Return File(pdf.BinaryData, "application/pdf", "viewToPdfMVCCore.pdf")
    End If

    Return View(persons)
End Function
NuGet Download
PM > Install-Package IronPdf
CSHTML to PDF (MVC Core)

CSHTML to PDF (MVC Core)

This code example demonstrates the process of converting Views into PDFs.

Two packages, IronPdf.Extensions.Mvc.Core and IronPdf, work together to enable the rendering of Views into PDFs. The IronPdf.Extensions.Mvc.Core package serves as an extension to IronPdf, enabling the rendering of Views to PDFs.

Use the RenderRazorViewToPdf method to render Views to PDFs. This method requires an IRazorViewRenderer, the path to the ".cshtml" file, and the data required to display on the ".cshtml" file. Please visit the How to Convert View to PDF in ASP.NET Core MVC how-to article to learn more.

This action also enables you to access the full range of features provided by the RenderingOptions class, such as applying page numbers in PDFs with IronPDF, adding text and HTML headers and footers with IronPDF, and customizing PDF paper size. The resulting PDF document can be further edited or exported as needed.

Learn to Convert CSHTML Views to PDFs in ASP.NET MVC Core.
View on GitHub

Ready to Get Started?

Nuget Downloads 20,809,720Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required