Hi @MiKhel Navarra,
Add the following style to the separate css file(e.g site.css):
/* Styles for printing */
@media print {
body *
{
visibility: hidden; /* Hide everything in body by default */
}
#employeesTable, #employeesTable * {
visibility: visible; /* Make the printable table and its contents visible */
}
#employeesTable {
position: absolute;
left: 0;
top: 0;
}
}
Be sure your view like below:
<table id="employeesTable">
<!-- Table contents -->
</table>
<button onclick="window.print();">Print Table</button>
_Layout.cshtml:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"]</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<!--Your Custom Style-->
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
</head>
<body>
<header>
<!--Your header-->
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
<footer class="border-top footer text-muted">
<!--Your footer-->
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Rena