Orchardcore admin edit views

From OrchardCMS/OrchardCore · View interactive version

Orchardcore admin edit views is an AI agent skill from the GitHub repository OrchardCMS/OrchardCore. Creates and updates OrchardCore admin edit views using the ocat-* CSS class conventions, grouping their fields in cards declared by placement or ocat-card markup. Use when creating or modifying Edit view files (*.Edit.cshtml, *.Fields.Edit.cshtml) or the display drivers of admin editors, to ensure c

How to use this skill

Skill file

OrchardCore Admin Edit Views

This skill guides you through creating and updating admin edit view files using the ocat-* CSS class conventions required by the OrchardCore admin theme.

The `ocat-*` CSS Class System

The ocat-* CSS classes provide a standardized two-column layout for admin form fields. Every form field uses a consistent structure:

Core Classes

| Class | Element | Purpose |

|-------|---------|---------|

| ocat-wrapper | <div> | Outer container for a form field row (replaces mb-3/form-group) |

| ocat-label | <label>, or <span> for a caption | Styles the field label in the left column (replaces form-label) |

| ocat-label-required | <label> or <span> | Add alongside ocat-label to mark a field as required |

| ocat-end | <div> | Wraps the input, validation, and hint in the right column |

| ocat-end-offset | <div> | Right-column content with no left label (e.g., checkboxes) |

| ocat-limited-wrapper | <div> | Outer row for limited-width controls such as short text, numbers, selects, or small settings inputs |

| ocat-limited | <div> | Constrains the control width inside ocat-limited-wrapper |

Choosing the Right Wrapper

Use this decision guide when creating or updating admin edit views:

| Scenario | Preferred Pattern |

|----------|-------------------|

| Standard full-width field row | ocat-wrapper + ocat-label + ocat-end |

| Standalone checkbox/toggle row with no left label | ocat-wrapper + ocat-end-offset |

| Standalone alert or notice in the form flow | ocat-wrapper + ocat-end-offset |

| A group of fields (a section of the form) | A card, see Grouping Fields in Cards |

| Top-level limited-width field row (small text, number, select, token, path, port, etc.) | ocat-limited-wrapper + ocat-label + ocat-limited |

| Content part / content field editor that already needs wrapper classes like field-wrapper-* or content-part-wrapper-* | Keep the outer ocat-wrapper, then place ocat-limited-wrapper inside ocat-end |

Wrapper Selection Rules

  1. Use ocat-wrapper for the default admin edit-view row structure.
  2. Use ocat-limited-wrapper when the field should stay visually narrow instead of stretching the full editor width.
  3. If the outer row also needs Orchard-specific wrapper classes such as field-wrapper-* or content-part-wrapper-*, do not replace that outer row with ocat-limited-wrapper; keep the outer ocat-wrapper and nest ocat-limited-wrapper inside ocat-end.
  4. Do not use legacy helpers or Bootstrap-only layout classes like mb-3, form-group, form-label, @Orchard.GetWrapperClasses(), or @Orchard.GetLimitedWidthWrapperClasses().
  5. Alerts, notices, <legend>, and section headings that are part of the edit form but have no left-column label should use their own ocat-wrapper + ocat-end-offset row.
  6. A single row should use either ocat-end or ocat-end-offset, never both.

Labels and IDs

A <label> must be associated with one labelable control (input other than hidden, select, textarea, button) that is rendered on the page: its for matches the control's id, or it wraps the control.

  1. One control: <label asp-for="X"> and <input asp-for="X">. Both generate the same id.
  2. Several controls, or a widget without a control of that id (a list of checkboxes or radio buttons, a picker rendered by a script into a hidden input): caption the row with a <span> and label the container of the controls with it. See Group of Controls. Never point a label at a hidden input or at a property that renders no element with that id.
  3. A value without a control (read-only text, a date, a count): use a <span class="ocat-label">, see Display-Only Fields.
  4. A control generated by a script: give it an id derived from a server-rendered id (for example the id of its hidden input plus a suffix), so it is unique when the editor is rendered more than once on a page, and point the visible label at it. Use aria-label only when the control has no visible label.
  5. IDs are unique. asp-for always renders an id: when the same property is rendered twice (a hidden copy of a disabled select, a hidden input repeated in a loop), keep asp-for and set an explicit id, e.g. id="@Html.IdFor(m => m.Scope)_Hidden", which replaces the generated one.
  6. Every input, select and textarea has a name or an id, including search boxes and inputs that are not posted.

Standard Field Structure

<div class="ocat-wrapper" asp-validation-class-for="FieldName">
    <label asp-for="FieldName" class="ocat-label">@T["Label Text"]</label>
    <div class="ocat-end">
        <input asp-for="FieldName" class="form-control" />
        <span asp-validation-for="FieldName"></span>
        <span class="hint">@T["Descriptive hint text."]</span>
    </div>
</div>

Grouping Fields in Cards

Every admin form groups its fields in cards, so that a form reads as a few logical sections, e.g. "Server", "Authentication" and "Sender" for the SMTP settings, instead of one long column of fields. A card has a short title, a noun phrase in sentence case, and optionally a one-line description.

Every card comes from placement: views never write card markup.

Screens built by display drivers: cards come from placement

Screens composed of the shapes of display drivers (site settings, users, roles, content type, part and field settings, workflow activities, deployment steps, admin menu nodes, sitemap sources, rule conditions, ...) render the shapes in a content zone, which groups the shapes placed in the same card. Declare the card in the placement location of the shape, never with markup in its view:

internal readonly IStringLocalizer S;

public SmtpSettingsDisplayDriver(IStringLocalizer<SmtpSettingsDisplayDriver> stringLocalizer)
{
    S = stringLocalizer;
}

public override IDisplayResult Edit(ISite site, SmtpSettings settings, BuildEditorContext context)
{
    return Combine(
        Initialize<SmtpSettingsViewModel>("SmtpSettingsServer_Edit", model => ...)
            .Location(l => l.Zone("Content", "1").Card(S["Server"], "10"))
            .OnGroup(GroupId),
        Initialize<SmtpSettingsViewModel>("SmtpSettingsAuthentication_Edit", model => ...)
            .Location(l => l.Zone("Content", "2").Card(S["Authentication"], "20"))
            .OnGroup(GroupId));
}
Content item editors

Content item editors are not grouped in cards: the editor shapes of content parts and content fields don't declare cards, and ContentPart.Edit.cshtml renders the parts as they are.

Admin pages with a form: an editor built by display drivers

A page of a controller that edits a view model (e.g. creating a template, editing an OpenID application) doesn't render the fields itself: it renders an editor built by the display drivers of its view model, so its cards come from placement too, and other modules can add fields or cards to it. OrchardCore.Templates (TemplateController, TemplateDisplayDriver) is the reference.

  1. The view model carries the editor: [BindNever] public IShape Editor { get; set; }.
  2. A display driver of the view model renders one shape per card, each a copy of the view model, and binds the fields of its shapes. It keeps the names the page posts (no TemplateViewModel. prefix), so the controller, its validation keys and the scripts of the page keep working:
internal sealed class TemplateDisplayDriver : DisplayDriver<TemplateViewModel>
{
    internal readonly IStringLocalizer S;

    public TemplateDisplayDriver(IStringLocalizer<TemplateDisplayDriver> stringLocalizer)
    {
        S = stringLocalizer;
    }

    public override IDisplayResult Edit(TemplateViewModel model, BuildEditorContext context)
    {
        return Combine(
            Initialize<TemplateViewModel>("TemplateGeneral_Edit", m => Populate(model, m))
                .Location(l => l.Zone("Content", "1").Card(S["General"], "10")),
            Initialize<TemplateViewModel>("TemplateContent_Edit", m => Populate(model, m))
                .Location(l => l.Zone("Content", "2").Card(S["Template"], "20")));
    }

    public override async Task<IDisplayResult> UpdateAsync(TemplateViewModel model, UpdateEditorContext context)
    {
        await context.Updater.TryUpdateModelAsync(model, Prefix, m => m.Name, m => m.Description, m => m.Content);

        return Edit(model, context);
    }

    // The fields keep the names the page posts, which the controller validates and the scripts of the page select.
    protected override void BuildPrefix(TemplateViewModel model, string htmlFieldPrefix)
    {
        Prefix = htmlFieldPrefix ?? string.Empty;
    }

    private static void Populate(TemplateViewModel source, TemplateViewModel model)
    {
        model.Name = source.Name;
        // ...
    }
}

Register it with services.AddDisplayDriver<TemplateViewModel, TemplateDisplayDriver>(). Each shape has its own view (TemplateGeneral.Edit.cshtml, @model TemplateViewModel) holding only its rows. Use Initialize<T>, not View(shapeType, model): the latter wraps the model in a ShapeViewModel<T>, which renames the fields Value.Name.

  1. The root template of the editor, named after the view model, renders its zones: TemplateViewModel.Edit.cshtml holds @await DisplayAsync(Model.Content).
  2. The controller injects IDisplayManager<TemplateViewModel> and IUpdateModelAccessor. Its GET actions set model.Editor = await _displayManager.BuildEditorAsync(model, _updateModelAccessor.ModelUpdater, isNew), and its POST actions, once the model is bound, model.Editor = await _displayManager.UpdateEditorAsync(model, _updateModelAccessor.ModelUpdater, isNew) before validating and saving as before. Every path returning the view sets the editor.
  3. The page view keeps the form, its hidden inputs, its buttons and the scripts of the page, and renders the fields with @await DisplayAsync(Model.Editor).

How cards render

The admin theme renders a card (the Card shape) as a <fieldset> titled by its <legend>, the HTML element grouping related fields, styled as a Bootstrap card, or as a plain fieldset in a tab (e.g. the general, email and SMS settings) unless it holds a table, such as the events of the audit trail, always expanded: cards group fields, they don't hide them, so never group fields in an accordion, a collapse or a <details> element. Views never write card markup themselves.

<fieldset class="card mb-3 ocat-card">
    <legend class="card-header fs-6 mb-0 ocat-card-title">Server</legend>
    <div class="card-body ocat-card-body">...</div>
</fieldset>

Selecting content types

To select content types, render the SelectContentTypes view component of OrchardCore.Contents instead of a list of checkboxes: a searchable bootstrap-select picker that shows the selected content types as tags, with select all and deselect all. It posts the selected names under htmlName, as checkboxes sharing that name would.

@await Component.InvokeAsync("SelectContentTypes", new { selectedContentTypes = Model.ContentTypes, htmlName = Html.NameFor(m => m.ContentTypes) })

Pass stereotype to list the content types of a stereotype, displayMode = "Picker" for a filter where no selection means any content type, or displayMode = "Checkboxes" for the checkbox list.

Field Type Templates

Text Input

<div class="ocat-wrapper" asp-validation-class-for="FieldName">
    <label asp-for="FieldName" class="ocat-label">@T["Label"]</label>
    <div class="ocat-end">
        <input asp-for="FieldName" class="form-control" />
        <span asp-validation-for="FieldName"></span>
        <span class="hint">@T["Hint text."]</span>
    </div>
</div>

Required Text Input

Every field whose editor rejects an empty value ([Required], a model error on empty, or an HTML required attribute) gets ocat-label-required on its label. Add it conditionally when the field is only required in some states, e.g. @(settings.Required ? "ocat-label-required" : null), and don't add it to fields whose empty value is accepted or generated.

<div class="ocat-wrapper" asp-validation-class-for="FieldName">
    <label asp-for="FieldName" class="ocat-label ocat-label-required">@T["Label"]</label>
    <div class="ocat-end">
        <input asp-for="FieldName" class="form-control" />
        <span asp-validation-for="FieldName"></span>
        <span class="hint">@T["Hint text."]</span>
    </div>
</div>

Code/Script Input

<div class="ocat-wrapper" asp-validation-class-for="Expression">
    <label asp-for="Expression" class="ocat-label">@T["Expression"]</label>
    <div class="ocat-end">
        <input type="text" asp-for="Expression" class="form-control code" />
        <span asp-validation-for="Expression"></span>
        <span class="hint">@T["A JavaScript expression. Example: {0}", "input(\"Count\") > 0"]</span>
    </div>
</div>

Textarea

<div class="ocat-wrapper" asp-validation-class-for="Content">
    <label asp-for="Content" class="ocat-label">@T["Content"]</label>
    <div class="ocat-end">
        <textarea asp-for="Content" class="form-control" rows="5"></textarea>
        <span asp-validation-for="Content"></span>
        <span class="hint">@T["Hint text."]</span>
    </div>
</div>

Select / Dropdown

<div class="ocat-wrapper" asp-validation-class-for="FieldName">
    <label asp-for="FieldName" class="ocat-label">@T["Label"]</label>
    <div class="ocat-end">
        <select asp-for="FieldName" class="form-select">
            <option value="Option1">@T["Option 1"]</option>
            <option value="Option2">@T["Option 2"]</option>
        </select>
        <span asp-validation-for="FieldName"></span>
        <span class="hint">@T["Hint text."]</span>
    </div>
</div>

Checkbox (No Left Label)

Use ocat-end-offset when there is no label in the left column (e.g., for checkboxes):

<div class="ocat-wrapper" asp-validation-class-for="IsEnabled">
    <div class="ocat-end-offset">
        <div class="form-check">
            <input type="checkbox" class="form-check-input" asp-for="IsEnabled" />
            <label asp-for="IsEnabled" class="form-check-label">@T["Enable feature"]</label>
        </div>
        <span class="hint dashed">@T["Check to enable this feature."]</span>
    </div>
</div>

Group of Controls

Use this when the left-column caption applies to several controls, such as a list of checkboxes or radio buttons, or to a widget rendered by a script. The caption is a <span> with an id, and the container of the controls is a group (radiogroup for radio buttons) labelled by it. Each control keeps its own label.

<div class="ocat-wrapper" asp-validation-class-for="ContentTypes">
    <span id="@Html.IdFor(m => m.ContentTypes)_Label" class="ocat-label">@T["Content types"]</span>
    <div class="ocat-end" role="group" aria-labelledby="@Html.IdFor(m => m.ContentTypes)_Label">
        @for (var i = 0; i < Model.ContentTypes.Length; i++)
        {
            <div class="form-check">
                <input type="checkbox" class="form-check-input" asp-for="ContentTypes[i].IsSelected" />
                <label class="form-check-label" asp-for="ContentTypes[i].IsSelected">@Model.ContentTypes[i].DisplayName</label>
            </div>
        }
        <span asp-validation-for="ContentTypes"></span>
        <span class="hint">@T["The content types to include."]</span>
    </div>
</div>

Headline / Alert Row (No Left Label)

Use this for standalone form guidance or warnings. To start a new section of a form, use a card instead of a heading row (see Grouping Fields in Cards):

<div class="ocat-wrapper">
    <div class="ocat-end-offset">
        <div class="alert alert-warning" role="alert">
            @T["Important information for editors."]
        </div>
    </div>
</div>

Input Group (with prefix/suffix)

<div class="ocat-wrapper" asp-validation-class-for="Url">
    <label asp-for="Url" class="ocat-label">@T["URL"]</label>
    <div class="ocat-end">
        <div class="input-group">
            <span class="input-group-text">https://</span>
            <input asp-for="Url" type="text" class="form-control" />
        </div>
        <span asp-validation-for="Url"></span>
        <span class="hint">@T["The full URL."]</span>
    </div>
</div>

Limited-Width Field Row

Use this when the whole row is a compact admin field, such as a page size, port, callback path, or select list:

<div class="ocat-limited-wrapper" asp-validation-class-for="PageSize">
    <label asp-for="PageSize" class="ocat-label">@T["Page size"]</label>
    <div class="ocat-limited">
        <input asp-for="PageSize" type="number" class="form-control" />
        <span asp-validation-for="PageSize"></span>
        <span class="hint">@T["The default page size."]</span>
    </div>
</div>

Limited-Width Select Row

<div class="ocat-limited-wrapper" asp-validation-class-for="TimeZone">
    <label asp-for="TimeZone" class="ocat-label">@T["Default Time Zone"]</label>
    <div class="ocat-limited">
        <select asp-for="TimeZone" class="form-select">
            <option value="">@T["Local to server"]</option>
        </select>
        <span asp-validation-for="TimeZone"></span>
        <span class="hint">@T["Determines the default time zone."]</span>
    </div>
</div>

Limited-Width Control Inside a Field Wrapper

Use this when the editor already needs a content field or content part wrapper on the outer row:

<div class="@($"ocat-wrapper field-wrapper field-wrapper-{Model.PartFieldDefinition.PartDefinition.Name.HtmlClassify()}-{Model.PartFieldDefinition.Name.HtmlClassify()}")">
    <label asp-for="Value" class="ocat-label">@T["Value"]</label>
    <div class="ocat-end">
        <div class="ocat-limited-wrapper">
            <div class="ocat-limited">
                <input asp-for="Value" class="form-control" />
                <span asp-validation-for="Value"></span>
            </div>
        </div>
        <span class="hint">@T["Use a compact editor width while preserving the field wrapper row."]</span>
    </div>
</div>

Conditional Fields with JavaScript/Liquid Syntax Selector

For fields that support both JavaScript and Liquid syntax, use the syntax selector pattern with toggling d-none:

<div class="ocat-wrapper" asp-validation-class-for="Syntax">
    <label asp-for="Syntax" class="ocat-label">@T["Syntax"]</label>
    <div class="ocat-end">
        <select asp-for="Syntax" class="form-select">
            <option value="@nameof(WorkflowScriptSyntax.JavaScript)">@T["JavaScript"]</option>
            <option value="@nameof(WorkflowScriptSyntax.Liquid)">@T["Liquid"]</option>
        </select>
        <span asp-validation-for="Syntax"></span>
    </div>
</div>

<div id="@(Html.IdFor(m => m.Expression))_group" class="ocat-wrapper @(Model.Syntax == WorkflowScriptSyntax.JavaScript ? "" : "d-none")" asp-validation-class-for="Expression">
    <label asp-for="Expression" class="ocat-label">@T["Expression"]</label>
    <div class="ocat-end">
        <input type="text" asp-for="Expression" class="form-control code" />
        <span asp-validation-for="Expression"></span>
        <span class="hint">@T["A JavaScript expression. Example: {0}", "input(\"Count\") > 0"]</span>
    </div>
</div>

<div id="@(Html.IdFor(m => m.LiquidExpression))_group" class="ocat-wrapper @(Model.Syntax == WorkflowScriptSyntax.Liquid ? "" : "d-none")" asp-validation-class-for="LiquidExpression">
    <label asp-for="LiquidExpression" class="ocat-label">@T["Expression"]</label>
    <div class="ocat-end">
        <input type="text" asp-for="LiquidExpression" class="form-control code" />
        <span asp-validation-for="LiquidExpression"></span>
        <span class="hint">@T["A Liquid expression. Example: {0}", "{{ Workflow.Properties.Value }}"]</span>
    </div>
</div>

<script at="Foot">
    document.addEventListener('DOMContentLoaded', () => {
        const syntaxElement = document.getElementById('@Html.IdFor(m => m.Syntax)');
        const javaScriptGroup = document.getElementById('@($"{Html.IdFor(m => m.Expression)}_group")');
        const liquidGroup = document.getElementById('@($"{Html.IdFor(m => m.LiquidExpression)}_group")');

        const toggleEditors = () => {
            const useLiquid = syntaxElement.value === '@nameof(WorkflowScriptSyntax.Liquid)';
            javaScriptGroup.classList.toggle('d-none', useLiquid);
            liquidGroup.classList.toggle('d-none', !useLiquid);
        };

        syntaxElement.addEventListener('change', toggleEditors);
        toggleEditors();
    });
</script>

Display-Only Fields (Read-Only)

For displaying information without a form input, the caption is a <span>, since a <label> needs a control:

<div class="ocat-wrapper">
    <span class="ocat-label">@T["Field Label"]</span>
    <div class="ocat-end">
        <span>@Model.FieldValue</span>
    </div>
</div>

Action Bar

Render the submit buttons of an admin edit page in a <div class="action-bar-bottom">, the last child of the form. The admin theme fixes it to the bottom of the viewport. Order its children from the least to the most important action, the same on every page:

  1. Cancel (or Back) first, a btn-secondary link with the cancel class.
  2. The secondary actions, marked with action-bar-secondary: alternative saves such as Save & Configure, Preview, Delete. In the Menu actions layout and on small screens they move into the "more actions" menu, opened by the ⋮ toggle at the end of the bar, where destructive actions are listed last.
  3. The main action last, such as Save, Create or Publish, or its btn-group with a Save and continue dropdown.

Keep the DOM in this order instead of reordering with CSS, so the keyboard focus follows what is shown. Use the same button styles on every page: btn-secondary for Cancel and alternative actions (e.g. Save & Configure, Create & Setup), btn-danger for destructive ones, and btn-primary for the main action. Only the content item Publish button uses btn-success, to stand apart from Save Draft.

Modal dialog footers (.modal-footer, and the dialog opened by confirmDialog()) use the same order: Cancel or Close first, any secondary action (e.g. Reset Anchor) next, and the confirming action (OK, Save, Delete) last.

<div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@T["Cancel"]</button>
    <button type="button" class="btn btn-primary" v-on:click="save">@T["OK"]</button>
</div>
<div class="action-bar-bottom">
    <a class="btn btn-secondary cancel" role="button" asp-action="Index">@T["Cancel"]</a>
    <a class="btn btn-danger action-bar-secondary" asp-action="Delete" data-url-af="RemoveUrl UnsafeUrl">@T["Delete"]</a>
    <button class="btn btn-primary save" type="submit">@T["Save"]</button>
</div>

Shapes placed in an Actions zone follow the same order through their positions: on content items Preview is at Actions:5, Delete 10, Unpublish 20, Save Draft 30 and Publish 40, and the content editor renders Cancel before the zone.

Migration: Old to New Classes

When updating existing views, apply these replacements:

| Old Pattern | New Pattern |

|-------------|-------------|

| <div class="mb-3" ...> | <div class="ocat-wrapper" ...> |

| <div class="form-group" ...> | <div class="ocat-wrapper" ...> |

| <label ... class="form-label"> | <label ... class="ocat-label"> |

| Input/select/textarea directly inside wrapper | Wrap in <div class="ocat-end"> |

| Checkbox with label inside wrapper | Wrap in <div class="ocat-end-offset"><div class="form-check"> |

| Standalone headline or alert directly in the form flow | Wrap in <div class="ocat-wrapper"><div class="ocat-end-offset">...</div></div> |

| Mixing ocat-end and ocat-end-offset in one row | Choose one wrapper based on whether there is a left-column label |

| <label> captioning several controls, a hidden input or a read-only value | <span class="ocat-label">, with role="group" and aria-labelledby on the controls' container |

| @Orchard.GetLimitedWidthWrapperClasses() | ocat-limited-wrapper |

| @Orchard.GetLimitedWidthClasses() | ocat-limited |

| Limited-width content field row using field-wrapper-* | Keep outer ocat-wrapper field-wrapper-*, nest ocat-limited-wrapper inside ocat-end |

Complete Edit View Example

@model MyModuleViewModel

<div class="ocat-wrapper" asp-validation-class-for="Title">
    <label asp-for="Title" class="ocat-label ocat-label-required">@T["Title"]</label>
    <div class="ocat-end">
        <input asp-for="Title" class="form-control" autofocus="autofocus" />
        <span asp-validation-for="Title"></span>
        <span class="hint">@T["The title of the item."]</span>
    </div>
</div>

<div class="ocat-wrapper" asp-validation-class-for="Description">
    <label asp-for="Description" class="ocat-label">@T["Description"]</label>
    <div class="ocat-end">
        <textarea asp-for="Description" class="form-control" rows="4"></textarea>
        <span asp-validation-for="Description"></span>
        <span class="hint">@T["A brief description."]</span>
    </div>
</div>

<div class="ocat-wrapper" asp-validation-class-for="Category">
    <label asp-for="Category" class="ocat-label">@T["Category"]</label>
    <div class="ocat-end">
        <select asp-for="Category" class="form-select">
            <option value="">@T["-- Select --"]</option>
            <option value="A">@T["Category A"]</option>
            <option value="B">@T["Category B"]</option>
        </select>
        <span asp-validation-for="Category"></span>
    </div>
</div>

<div class="ocat-wrapper" asp-validation-class-for="IsPublished">
    <div class="ocat-end-offset">
        <div class="form-check">
            <input type="checkbox" class="form-check-input" asp-for="IsPublished" />
            <label asp-for="IsPublished" class="form-check-label">@T["Published"]</label>
        </div>
        <span class="hint dashed">@T["Check to publish this item."]</span>
    </div>
</div>

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.