In this article I will explain with an example, how to render Partial View inside Bootstrap Modal Popup in ASP.Net MVC Razor.
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 MVC Razor.
 
 
Database
Here I am making use of Microsoft’s Northwind Database. You can download it from here.
 
 
Configuring and connecting Entity Framework to database
Now I will explain the steps to configure and add Entity Framework and also how to connect it with the database.
You will need to add Entity Data Model to your project by right clicking the Solution Explorer and then click on Add and then New Item option of the Context Menu.
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
From the Add New Item window, select ADO.NET Entity Data Model and set its Name as NorthwindModel and then click Add.
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
Then the Entity Data Model Wizard will open up where you need to select EF Designer database option.
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
Now the wizard will ask you to connect and configure the Connection String to the database.
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
You will need to select the
1.     SQL Server Instance
2.     Database
And then click Test Connection to make sure all settings are correct.
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
Once the Connection String is generated, click Next button to move to the next step.
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
Next you will need to choose the Entity Framework version to be used for connection.
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
Now you will need to choose the Tables you need to connect and work with Entity Framework. Here Customers Table is selected.
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
The above was the last step and you should now have the Entity Data Model ready with the Customers Table of the Northwind Database.
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
 
Controller
The Controller consists of two Action methods.
Action method for handling GET operation
Inside this Action method, the Top 10 Customer records are fetched from the Customers Table of the Northwind Database and returned to the View.
 
Action method for handling jQuery POST operation
This Action method handles the call made from the jQuery AJAX function from the View.
The value of the customerId parameter is used to fetch the Customer record using Entity Framework which is then used to populate the Details Partial View.
Finally, the Partial View is returned from the Controller.
public class HomeController : Controller
{
    // GET: Home
    public ActionResult Index()
    {
        NorthwindEntities entities = new NorthwindEntities();
        return View(from customer in entities.Customers.Take(10)
                    select customer);
    }
 
    [HttpPost]
    public ActionResult Details(string customerId)
    {
        NorthwindEntities entities = new NorthwindEntities();
        return PartialView("Details", entities.Customers.Find(customerId)); 
    }
}
 
 
View
Now you will need to Right Click inside the Controller class and click on the Add View option in order to create a View for the Controller.
The Name of the View is set to Index, the Template option is set to Empty, the Model class is set to Customer Entity (the one we have generated using Entity Framework) and finally the Data context class is set to NorthwindEntities.
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
Inside the View, in the very first line the Customer Entity is declared as IEnumerable which specifies that it will be available as a Collection.
For displaying the records, an HTML Table is used. 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 HTML Anchor Link is clicked, a jQuery AJAX Call is made to the Details Action method of the Controller and the Details 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 Controller’s Action method in ASP.Net MVC, please refer my article ASP.Net MVC: jQuery AJAX and JSON Example.
 
@model IEnumerable<Partial_View_MVC.Customer>
 
@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <title>Index</title>
</head>
<body>
    <h4>Customers</h4>
    <hr/>
    <table cellpadding="0" cellspacing="0" class="grid" id="CustomerGrid">
        <tr>
            <th>CustomerID</th>
            <th>Contact Name</th>
            <th>City</th>
            <th>Country</th>
            <th></th>
        </tr>
        @foreach (Customer customer in Model)
        {
            <tr>
                <td>@customer.CustomerID</td>
                <td>@customer.ContactName</td>
                <td>@customer.City</td>
                <td>@customer.Country</td>
                <td><a class="details" href="javascript:;">View</a></td>
            </tr>
        }
    </table>
    <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>
                    </button>
                </div>
                <div class="modal-body">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"/>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" 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();
                $.ajax({
                    type: "POST",
                    url: "/Home/Details",
                    data: '{customerId: "' + customerId + '" }',
                    contentType: "application/json; charset=utf-8",
                    dataType: "html",
                    success: function (response) {
                        $("#partialModal").find(".modal-body").html(response);
                        $("#partialModal").modal('show');
                    },
                    failure: function (response) {
                        alert(response.responseText);
                    },
                    error: function (response) {
                        alert(response.responseText);
                    }
                });
            });
        });
    </script>
</body>
</html>
 
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
 
Partial View
In order to add Partial View, you will need to Right Click inside the Controller class and click on the Add View option in order to create a View for the Controller.
The Name of the View is set to Details, the Template option is set to Empty, the Model class is set to Customer Entity (the one we have generated using Entity Framework), the Data context class is set to NorthwindEntities and finally the Create as a partial view option needs to be checked.
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
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 is displayed using the Html.DisplayFor helper method.
@model Partial_View_MVC.Customer
 
<table cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td valign="top"><b>@Html.DisplayNameFor(model => model.Address):</b></td>
        <td>
            @Html.DisplayFor(model => model.Address)
            <br/>
            @Html.DisplayFor(model => model.City),
            @Html.DisplayFor(model => model.PostalCode)
            <br/>
            @Html.DisplayFor(model => model.Country)
        </td>
    </tr>
</table>
 
 
Screenshot
Render Partial View inside Bootstrap Modal Popup in ASP.Net MVC
 
 
Downloads