Overview

Create and edit pages for your resources

Introduction

A resource's create and edit pages display a form for adding or editing a record. You can enable these pages for a resource by calling the AllowCreate() and AllowEdit() methods respectively. Each of these give you form builder that allows you to configure fields by calling the Fields() method.

The example below adds a create and edit page for trips:

admin.AddEfCoreResource<Trip>(resource =>
{
    resource.AllowCreate(create => create.Fields(fields =>
    {
        fields.Add(trip => trip.Title);
        fields.Add(trip => trip.DestinationId);
        fields.Add(trip => trip.BasePrice);
    }));

    resource.AllowEdit(edit => edit.Fields(fields =>
    {
        fields.Add(trip => trip.Title);
        fields.Add(trip => trip.DestinationId);
        fields.Add(trip => trip.BasePrice);
        fields.Add(trip => trip.IsPublished);
    }));
});

Once a user submits a form, StellarAdmin will validate the form, save the data, and return the user to the resource's index page.

You can read more about configuring forms on these pages:

  • Fields covers the basics: labels, help text, and read-only or disabled fields.
  • Layout shows how to split a long form into sections and arrange fields in columns.
  • Setting default values explains how to set the values when adding a new record.
  • Validating forms shows how to validate the data on the form.
  • Choosing an editor explains how to specify the editor for a field.
  • Form events shows how to run your own code when an EF Core form loads or saves a record.
  • Form models explains how create forms that contain additional fields that are not part of the resource model, for example a password confirmation field.

Changing the title and button label

You can change the edit or create page's title and submit button label in the form builder. The example below changes the edit page's title and the label of its submit button:

resource.AllowEdit(edit =>
{
    edit.Title = "Edit trip details";
    edit.SubmitLabel = "Save changes";
    edit.Fields(fields => fields.Add(trip => trip.Title));
});

The default values for these two properties are determined as follows:

PropertyCreate page defaultEdit page default
Title"Create" and the singular label, such as "Create Trip"The record's title, such as the trip's name. When the title is the key, "Edit" and the singular label, such as "Edit Trip"
SubmitLabel"Create" and the singular label, such as "Create Trip""Save" and the singular label, such as "Save Trip"

Rapid data capturing

Allow users to quickly capture multiple records by calling EnableAddAnother() on the create page's form builder. This adds a Save and add another button to the form.

The trip create page with Create Trip and Save and add another trip buttons

This button saves the record and resets the form, allowing the user to quickly capture multiple records without navigating back and forth.

Your users can use the Ctrl+Shift+Enter (Command+Shift+Enter on a Mac) shortcut to save and add a new record.

You can also allow the values of some fields to carry over to the next new record. For example, if you know your users typically capture a series of trips for a specific destination, you can indicate that the DestinationId must keep its value when resetting the form by calling KeepForNext().

resource.AllowCreate(create =>
{
    create.Fields(fields =>
    {
        fields.Add(trip => trip.Title);
        fields.Add(trip => trip.DestinationId);
        fields.Add(trip => trip.DurationDays);
    });
    create.EnableAddAnother(another =>
    {
        another.KeepForNext(trip => trip.DestinationId);
        another.Label = "Save and add another trip";
    });
});
SettingWhat it does
KeepForNext()Carries the field's value over to the next record. Call it once for each field to carry over.
LabelSets the button's label. The default is "Save and add another".

With inline editing, EnableAddAnother() adds the button to the new row instead.

On this page