In this article I will explain with an example, how to render Partial View inside Bootstrap Modal Popup in ASP.Net Core Razor Pages.
The Partial View will be populated and fetched using jQuery AJAX and finally it will be rendered as HTML inside Bootstrap Modal Popup in ASP.Net Core Razor Pages.
Note: For beginners in ASP.Net Core Razor Pages, please refer my article ASP.Net Core Razor Pages: Hello World Tutorial with Sample Program example.
Here I am making use of Microsoft’s Northwind Database. You can download it from here.
Note: The Customers Table of the Northwind Database will be used in this project.
Following class is used as the Model class.
public class Customer
    public string CustomerID { get; set; }
    public string ContactName { get; set; }
    public string Address { get; set; }
    public string City { get; set; }
    public string Country { get; set; }
    public string PostalCode { get; set; }
Entity Data Model
Following is the Database Context class which is used to connect to the Database.
Note: For more information on creating Database Context class using Entity Framework, please refer my article ASP.Net Core Razor Pages: Simple Entity Framework Tutorial with example.
using Razor_PartialView_EF_Core.Models;
using Microsoft.EntityFrameworkCore;
namespace Razor_PartialView_EF_Core
    public class DBCtx : DbContext
        public DBCtx(DbContextOptions<DBCtx> options) : base(options)
        public DbSet<Customer> Customers { get; set; }
You will need to import the following namespaces.
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Razor_PartialView_EF_Core.Models;
Razor PageModel (Code-Behind)
The Database Context class is injected into the IndexModel class using Dependency Injection method.
The IndexModel consists of the following Handler methods.
Handler method for handling GET operation
Inside the Handler method that handles the GET calls, the Top 10 records are fetched from the Customers Table of the Northwind Database and returned to the Razor Page.
Handler method for handling jQuery POST operation
This Handler method handles the call made from the jQuery AJAX function from the Razor Page.
Note: The following Handler method handles jQuery AJAX call for returning Partial View and hence the return type is set to PartialViewResult. For more details, please refer my article Using jQuery AJAX in ASP.Net Core Razor Pages.
The value of the customerId parameter is used to fetch the Customer records using Entity Framework which is then used to populate the Details Partial Razor View.
The Customer records are added to ViewDataDictionary collection which is then set in the PartialViewResult object.
Finally, the PartialViewResult object is returned to the Details Partial Razor View.
public class IndexModel : PageModel
    private DBCtx Context { get; }
    public IndexModel(DBCtx _context)
        this.Context = _context;
    public List<Customer> Customers { get; set; }
    public void OnGet()
        this.Customers = (from customer in this.Context.Customers.Take(10)
                          select customer).ToList();
    public PartialViewResult OnPostGetDetails(string customerId)
        return new PartialViewResult
            ViewName = "Details",
            ViewData = new ViewDataDictionary<Customer>(ViewData, this.Context.Customers.Find(customerId))
Razor Page (HTML)
The HTML of Razor Page consists of an HTML Table.
A loop will be executed over the Model which will generate the HTML Table rows with the Customer Table records.
The last column of the HTML Table consists of an HTML Anchor Link. The HTML Anchor Link has been assigned a jQuery Click event handler.
When the View HTML Anchor Link is clicked, a jQuery AJAX Call is made to the GetDetails Handler method and the Details Razor Partial View is fetched as HTML which is finally displayed using Bootstrap Modal Popup window.
Note: For more details on how to use jQuery AJAX for calling Handler method in ASP.Net Core Razor Pages, please refer my article Using jQuery AJAX in ASP.Net Core Razor Pages.
@model Razor_PartialView_EF_Core.Pages.IndexModel
@using Razor_PartialView_EF_Core.Models
    Layout = null;
<!DOCTYPE html>
    <meta name="viewport" content="width=device-width" />
    <table cellpadding="0" cellspacing="0" class="grid" id="CustomerGrid">
            <th>Contact Name</th>
        @foreach (Customer customer in Model.Customers)
                <td><a class="details" href="javascript:;">View</a></td>
    <div id="partialModal" class="modal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Customer Details Form</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                <div class="modal-body">
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
    <script type="text/javascript" src=""></script>
    <link rel="stylesheet" href="" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous" />
    <script src="" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <script type="text/javascript">
        $(function () {
            $("#CustomerGrid .details").click(function () {
                var customerId = $(this).closest("tr").find("td").eq(0).html();
                    type: "POST",
                    url: "/Index?handler=GetDetails",
                    beforeSend: function (xhr) {
                    data: { "customerId": customerId },
                    success: function (response) {
                    failure: function (response) {
                    error: function (response) {
Render Partial View inside Bootstrap Modal Popup in ASP.Net Core Razor Pages
Partial View
In order to add Partial View, you will need to Right Click inside the Solution Explorer and click on the Add New Item option in order to add a Partial Razor View.
Inside the Add New Item dialog, the Razor View – Empty options needs to be selected as shown below.
Render Partial View inside Bootstrap Modal Popup in ASP.Net Core Razor Pages
Inside the Partial View, in the very first line the Customer Entity is declared as Model for the Partial View. The details of the Customer are displayed using the Html.DisplayFor helper method.
@model Razor_PartialView_EF_Core.Models.Customer
<table cellpadding="0" cellspacing="0" border="0">
        <td valign="top"><b>@Html.DisplayNameFor(model => model.Address):</b></td>
            @Html.DisplayFor(model => model.Address)
            @Html.DisplayFor(model => model.City),
            @Html.DisplayFor(model => model.PostalCode)
            @Html.DisplayFor(model => model.Country)
Render Partial View inside Bootstrap Modal Popup in ASP.Net Core Razor Pages