Overview
A read-only page for one record
Introduction
You can give users a read-only view of a resource by using View pages.


Configuring a basic view page
Add a view page by calling AllowView() on the resource builder. To add fields to the page, call the Fields() method, which gives you a field builder.
The example below adds a view page for bookings that displays the booking's reference, trip and departure date:
admin.AddEfCoreResource<Booking>(resource =>
{
resource.AllowView(view => view.Fields(fields =>
{
fields.Add(booking => booking.Reference);
fields.Add(booking => booking.Departure.Trip);
fields.Add(booking => booking.Departure.StartDate);
}));
});StellarAdmin doesn't add fields automatically, so the page displays only the fields you add.
Configuring fields
Every field on a view page is a display field, so it has the same settings, such as Title, EmptyText and UseDisplay(). You configure them using the field builder that is passed in the callback parameter when calling Add().
A field can select a property of a related record, such as booking.Traveller.Email, or compute a value, such as the number of passengers. A field that selects a record of another resource, such as booking.Traveller, displays that record's title.
The example below sets the label of the passenger count and the traveller's email, renders the total as currency, and sets the text displayed when there are no special requests:
using StellarAdmin.Resources.Displays;
resource.AllowView(view => view.Fields(fields =>
{
fields.Add(booking => booking.Reference);
fields.Add(booking => booking.Passengers.Count, field => field.Title = "Travelers");
fields.Add(booking => booking.TotalAmount, field =>
{
field.UseDisplay<NumberDisplay>(number => number.Format = "C");
});
fields.Add(booking => booking.Traveller);
fields.Add(booking => booking.Traveller.Email, field => field.Title = "Email");
fields.Add(booking => booking.SpecialRequests, field => field.EmptyText = "No special requests");
}));To render a value differently, such as a badge or an image, see displays.
Using sections
A view page uses the same sections, groups and columns as a form. To split the page into sections, call AddSection() with the section's title. To place the sections side by side, call Columns().
The example below displays the booking in a Trip and a Traveller section, side-by-side over two columns:
using StellarAdmin.Resources.Displays;
resource.AllowView(view => view.Fields(fields =>
{
fields.Columns(2);
fields.AddSection("Trip", section =>
{
section.Add(booking => booking.Reference);
section.Add(booking => booking.Departure.Trip);
section.Add(booking => booking.Departure.StartDate);
section.Add(booking => booking.Passengers.Count, field => field.Title = "Travelers");
section.Add(booking => booking.TotalAmount, field =>
{
field.UseDisplay<NumberDisplay>(number => number.Format = "C");
});
});
fields.AddSection("Traveller", section =>
{
section.Add(booking => booking.Traveller);
section.Add(booking => booking.Traveller.Email, field => field.Title = "Email");
section.Add(booking => booking.SpecialRequests, field => field.EmptyText = "No special requests");
});
}));To change how the page's sections look, set the page's SectionLayout to one of the section layouts. To display each label beside its value instead of above it, set a section's Orientation to FieldOrientation.Horizontal.
The example below displays the page's sections in cards, and the Audit section's labels beside their values:
using StellarAdmin.UI;
resource.AllowView(view =>
{
view.SectionLayout = FormSectionLayout.Card;
view.Fields(fields =>
{
fields.AddSection("Audit", section =>
{
section.Orientation = FieldOrientation.Horizontal;
section.Add(booking => booking.BookedAt);
section.Add(booking => booking.UpdatedAt);
});
});
});Changing the title
The page's title defaults to the record's title, such as the booking's reference. To change it, set Title using the field builder passed in the AllowView() callback:
resource.AllowView(view =>
{
view.Title = "Booking details";
view.Fields(fields => fields.Add(booking => booking.Reference));
});Displaying a different model
To display something other than the resource's entity, such as a summary that combines several records, give the page its own model and a handler that loads it. Call AllowView() with the model and the handler as type arguments:
resource.AllowView<BookingSummary, BookingSummaryHandler>(view => view.Fields(fields =>
{
fields.Add(summary => summary.Reference);
fields.Add(summary => summary.Itinerary);
}));The handler implements IResourceViewHandler<T>. Its FindAsync() method loads the model for the record with the given key. Return null when the record doesn't exist, and StellarAdmin returns a 404. StellarAdmin registers the handler as a scoped service, unless you've registered it already, so the handler can take any service in its constructor.
Without a handler, StellarAdmin loads the record through the resource's data source, which an EF Core resource already does. A custom data source must implement IResourceViewHandler<T>, which IResourceEditHandler<T> includes. If it doesn't, StellarAdmin leaves out the page and reports a configuration problem.
Adding content to the page
To add blocks such as stats or a list of related records above, beside or below the fields, add widgets.