Custom pages

Display your own Razor Pages and MVC views inside the admin panel

As mentioned in the Sidebar documentation, you can add links to pages from your own application to the sidebar. When doing so, you would probably also want those pages to have the same layout and navigation bar as the StellarAdmin pages, so it appears as one unified application.

You can achieve this by setting the layout of your own pages to use StellarAdminLayouts.Default. This ensure your pages share the same layout as the StellarAdmin pages. The example below lists the bookings that depart this week:

Pages/Admin/Departures.cshtml
@page
@model DeparturesModel
@using StellarAdmin
@addTagHelper *, StellarAdmin.UI
@{
    Layout = StellarAdminLayouts.Default;
    ViewData["Title"] = "Departures this week";
}

<sa-page-container>
    <sa-page-header>
        <sa-page-header-title>Departures this week</sa-page-header-title>
    </sa-page-header>
    <sa-table>
        <sa-table-header>
            <sa-table-row>
                <sa-table-head>Reference</sa-table-head>
                <sa-table-head>Departs</sa-table-head>
            </sa-table-row>
        </sa-table-header>
        <sa-table-body>
            @foreach (var booking in Model.Departures)
            {
                <sa-table-row>
                    <sa-table-cell>@booking.Reference</sa-table-cell>
                    <sa-table-cell>@booking.Departure.StartDate.ToString("d MMM yyyy")</sa-table-cell>
                </sa-table-row>
            }
        </sa-table-body>
    </sa-table>
</sa-page-container>
Pages/Admin/Departures.cshtml.cs
[Authorize(Roles = "Sales")]
public class DeparturesModel(ApplicationDbContext db) : PageModel
{
    public List<Booking> Departures { get; private set; } = [];

    public async Task OnGetAsync()
    {
        var today = DateOnly.FromDateTime(DateTime.Today);
        Departures = await db.Bookings
            .Include(booking => booking.Departure)
            .Where(booking => booking.Departure.StartDate >= today && booking.Departure.StartDate < today.AddDays(7))
            .OrderBy(booking => booking.Departure.StartDate)
            .ToListAsync();
    }
}
The Departures this week page inside the admin panel, with its link highlighted in the sidebar

ViewData["Title"] sets the page's name in the browser tab, such as "Departures this week - Voyager Travel".

To set the layout of every page in a folder, set it in a _ViewStart.cshtml in that folder instead.

Adding the page to the sidebar

To link to the page from the sidebar, call AddSidebarLink():

admin.AddSidebarLink("Departures this week", SidebarLinkTarget.Page("/Admin/Departures"), link =>
    link.Group = "Sales");

While the page is open, StellarAdmin highlights its link in the sidebar. See adding links to your own pages for the other targets and settings.

Protecting the page

The admin panel's authorization only protects StellarAdmin's own pages, so protect your page yourself, with [Authorize] or a Razor Pages authorization convention, as in the example above.

Styling the page

Build the page with the StellarAdmin.UI components, such as <sa-card> and <sa-table>. These are the same components that StellarAdmin uses and will ensure a unified look-and-feel.

On this page