Orchardcore admin edit views

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore admin edit views is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for writing Orchard Core admin editor views with the ocat CSS classes. Covers Edit views for content parts and fields, field editor variants, part and field settings editors, site settings editors, workflow activity and deployment step Fields.Edit views, and full admin edit pages, plus the oca

How to use this skill

Skill file

Orchard Core Admin Edit Views

Every admin view that edits something (a content part or field, a settings group, a workflow activity, a deployment step, or a module's own entity) lays out its rows with the static ocat- (Orchard Core Admin Theme) CSS classes. TheAdmin styles them as a stacked Bootstrap form; a custom admin theme can restyle every editor (for example as a horizontal form) by overriding the classes, without touching any view.

Which Views This Covers

| Editor | Produced by | View file |

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

| Content part editor | ContentPartDisplayDriver<TPart>.Edit with GetEditorShapeType(context) | Views/{Part}.Edit.cshtml |

| Content field editor | ContentFieldDisplayDriver<TField>.Edit with GetEditorShapeType(context) | Views/{Field}.Edit.cshtml |

| Field editor variant | The field's Editor setting | Views/{Field}-{Editor}.Edit.cshtml plus Views/{Field}-{Editor}.Option.cshtml (the <option> shown in the editor dropdown) |

| Part settings (per content type) | ContentTypePartDefinitionDisplayDriver<TPart> returning "{Part}Settings_Edit" at Content | Views/{Part}Settings.Edit.cshtml |

| Field settings | ContentPartFieldDefinitionDisplayDriver<TField> returning "{Field}Settings_Edit" at Content | Views/{Field}Settings.Edit.cshtml |

| Site settings group | SiteDisplayDriver<TSettings> with .OnGroup(...) | Views/{Name}Settings.Edit.cshtml |

| Workflow activity, deployment step | ActivityDisplayDriver / DeploymentStepDisplayDriver ({Name}_Fields_Edit) | Views/Items/{Name}.Fields.Edit.cshtml |

| Module entity page | Your admin controller action | Views/{Controller}/Edit.cshtml, Create.cshtml |

Shape-based editors (all rows except the last) render only their rows: the hosting page already owns the <form>, the validation summary, the title, and the Save button. Site settings get their Save button from the shared SiteSettings.SaveButton shape, so never add a form or a submit button to a settings editor.

The `ocat-*` Classes

| Class | Element | Purpose | Default TheAdmin style |

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

| ocat-wrapper | <div> | Outer container of one field row. Carries asp-validation-class-for. | margin-bottom: 1rem |

| ocat-label | <label> (or <div> for a group caption) | Field label in the leading column. | Like .form-label |

| ocat-label-required | <label> | Added next to ocat-label on every field whose editor rejects an empty value. | Appends a * in --bs-danger, with a 0.25rem inline-start padding (LTR and RTL) |

| ocat-end | <div> | Holds the control, its validation message, and its hint, after a label. | None (stacked) |

| ocat-end-offset | <div> | Same column with no label: checkboxes, switches, alerts, headings, buttons. | None (stacked) |

| ocat-start | <div> | Leading column container for content other than a label (alignment/push). | None (stacked) |

| ocat-limited-wrapper | <div> | Row (or inner wrapper) for a control that should stay narrow. | margin-bottom: 1rem |

| ocat-limited | <div> | Constrains the control width inside ocat-limited-wrapper. | 100%, 50% from md, 33.333% from lg, 25% from xxl |

Choosing the Row Pattern

| Row | Pattern |

|---|---|

| Labelled full-width field | ocat-wrapper > ocat-label + ocat-end |

| Required field | Same, with class="ocat-label ocat-label-required". Use it whenever the editor rejects an empty value ([Required], a model error on empty, or an HTML required attribute); add it conditionally when the field is required only in some states, e.g. @(settings.Required ? "ocat-label-required" : null), and never on fields whose empty value is accepted or generated |

| Checkbox or switch (its label is inline) | ocat-wrapper > ocat-end-offset > form-check |

| Alert, notice, <legend>, section heading, or buttons in the form flow | ocat-wrapper > ocat-end-offset |

| Short control (number, port, page size, select, short code or path) | ocat-limited-wrapper > ocat-label + ocat-limited |

| Short control in a part or field editor that needs content-part-wrapper-* / field-wrapper-* classes on the row | Keep the outer ocat-wrapper field-wrapper ..., nest ocat-limited-wrapper > ocat-limited inside ocat-end |

| Read-only value | ocat-wrapper > ocat-label + ocat-end holding text |

Layout Rules

  1. Every field row is an ocat-wrapper (or a top-level ocat-limited-wrapper). Never put an input, validation span, or hint directly in the wrapper.
  2. A row uses either ocat-end (it has a label) or ocat-end-offset (it has none), never both.
  3. Validation spans and hints go inside ocat-end / ocat-end-offset / ocat-limited (or inside the form-check of a checkbox).
  4. Standalone alerts, legends, headings, and action buttons get their own ocat-wrapper > ocat-end-offset row.
  5. To show or hide a row dynamically, toggle d-none on the ocat-wrapper itself, not on an inner element.
  6. Do not replace an outer row that carries field-wrapper-* or content-part-wrapper-* classes with ocat-limited-wrapper; nest the limited wrapper instead.
  7. Container editors (the inner editors of BagPart, FlowPart, WidgetsListPart, and Admin Menu node trees) keep their own card markup and do not use ocat-* inside; their outer content-part wrapper still does.

Row Templates

Text, Required, Code, Textarea, Select

<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 />
        <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="Expression">
    <label asp-for="Expression" class="ocat-label">@T["Expression"]</label>
    <div class="ocat-end">
        <input asp-for="Expression" class="form-control code" />
        <span asp-validation-for="Expression"></span>
        <span class="hint">@T["A Liquid expression. Example {0}", "{{ Model.Value }}"]</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>
    </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" asp-items="Model.Categories"></select>
        <span asp-validation-for="Category"></span>
    </div>
</div>

form-control code renders a monospace input for scripts, patterns, and expressions.

Checkbox, Alert, Heading, Buttons (No Label Column)

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

<div class="ocat-wrapper">
    <div class="ocat-end-offset">
        <h5>@T["Advanced"]</h5>
        <div class="alert alert-warning" role="alert">@T["Changing these values affects every tenant."]</div>
    </div>
</div>

Use form-check form-switch for a toggle. A settings editor that has nothing to edit can render its explanation in an ocat-end-offset alert row and return;.

Input Group

<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" class="form-control" />
        </div>
        <span asp-validation-for="Url"></span>
    </div>
</div>

When the validation message sits inside the input group (as in the user name and email editors), add has-validation to the group so Bootstrap keeps the rounded corners of the last control:

<div class="input-group has-validation">
    <span class="input-group-text"><i class="fa-solid fa-user" aria-hidden="true"></i></span>
    <input asp-for="UserName" class="form-control" />
    <span asp-validation-for="UserName" class="text-danger"></span>
</div>

Give every control an accessible name: an icon-only button gets aria-label (and title), and a checkbox whose label is visually empty holds <span class="visually-hidden">@T["Select {0}", name]</span>.

Limited Width

<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" min="1" class="form-control" />
        <span asp-validation-for="PageSize"></span>
        <span class="hint">@T["The default page size."]</span>
    </div>
</div>

Read-Only Value

<div class="ocat-wrapper">
    <label class="ocat-label">@T["Created"]</label>
    <div class="ocat-end">
        <span>@Model.CreatedUtc.ToString("g")</span>
    </div>
</div>

Conditional Rows

<div class="ocat-limited-wrapper">
    <label asp-for="Mode" class="ocat-label">@T["Mode"]</label>
    <div class="ocat-limited">
        <select asp-for="Mode" class="form-select" asp-items="Html.GetEnumSelectList<ExportMode>()"></select>
    </div>
</div>

<div id="@Html.IdFor(m => m.Schedule)_group" class="ocat-wrapper @(Model.Mode == ExportMode.Scheduled ? "" : "d-none")" asp-validation-class-for="Schedule">
    <label asp-for="Schedule" class="ocat-label">@T["Schedule"]</label>
    <div class="ocat-end">
        <input asp-for="Schedule" class="form-control code" />
        <span asp-validation-for="Schedule"></span>
    </div>
</div>

<script at="Foot">
    document.addEventListener('DOMContentLoaded', () => {
        const mode = document.getElementById('@Html.IdFor(m => m.Mode)');
        const group = document.getElementById('@(Html.IdFor(m => m.Schedule))_group');
        const toggle = () => group.classList.toggle('d-none', mode.value !== '@nameof(ExportMode.Scheduled)');

        mode.addEventListener('change', toggle);
        toggle();
    });
</script>

Admin scripts are plain DOM code: TheAdmin no longer loads jQuery. Larger scripts belong in a module script (<script asp-src="~/My.Module/Scripts/my-editor.min.js" at="Foot" type="module"></script>).

Validation

context.Updater.ModelState.AddModelError(Prefix, nameof(model.Pattern), S["A pattern is required when using the selected behavior."]);

Hints

@if (!string.IsNullOrEmpty(settings.Hint))
{
    @await DisplayAsync(await New.Hint_Admin(Hint: settings.Hint))
}

Content Part and Field Wrapper Classes

Part and field editors put these classes on the outer row so themes can target one content type's editor:

A field editor (Views/RatingField.Edit.cshtml) built like the shipped NumericField:

@model EditRatingFieldViewModel
@using OrchardCore.ContentManagement.Metadata.Models
@using OrchardCore.Mvc.Utilities
@{
    var settings = Model.PartFieldDefinition.GetSettings<RatingFieldSettings>();
    var partName = Model.PartFieldDefinition.PartDefinition.Name.HtmlClassify();
    var fieldName = Model.PartFieldDefinition.Name.HtmlClassify();
    var wrapperClasses = $"ocat-wrapper field-wrapper field-wrapper-{partName}-{fieldName}";

    if (Model.PartFieldDefinition.IsNamedPart())
    {
        wrapperClasses += $" field-wrapper-{Model.PartFieldDefinition.ContentTypePartDefinition.Name.HtmlClassify()}-{fieldName}";
    }
}

<div class="@wrapperClasses" id="@Html.IdFor(m => m.Value)_FieldWrapper" asp-validation-class-for="Value">
    <label asp-for="Value" class="ocat-label @(settings.Required ? "ocat-label-required" : "")">@Model.PartFieldDefinition.DisplayName()</label>
    <div class="ocat-end">
        <div class="ocat-limited-wrapper">
            <div class="ocat-limited">
                <input asp-for="Value" type="number" min="0" max="@settings.Maximum" class="form-control content-preview-select" />
                <span asp-validation-for="Value"></span>
            </div>
        </div>
        @if (!string.IsNullOrEmpty(settings.Hint))
        {
            @await DisplayAsync(await New.Hint_Admin(Hint: settings.Hint))
        }
    </div>
</div>

Shipped field editors localize the display name with IDataLocalizer (D[Model.PartFieldDefinition.DisplayName(), DataLocalizationContext.ContentField(...)]) when Data Localization is used. content-preview-text / content-preview-select classes let the Content Preview feature refresh on input.

Editor Groupings (Tabs, Cards, Columns)

Editor shapes are grouped by their placement location, not by markup in the view. Append modifiers to the zone and position:

| Modifier | Grouping | Example |

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

| #Name;order | Tab | Parts:1#Settings;2 |

| %Name;order | Card | Parts:1%Details;1 |

| \|Name_width;order | Column (Bootstrap col-md-{width}, or _lg-9 for another breakpoint) | Parts:1\|Main_9;1 |

return Initialize<MyPartViewModel>(GetEditorShapeType(context), model => model.Value = part.Value)
    .Location(l => l.Zone("Parts", "2").Tab("Settings", "1"));

Full Admin Edit Pages

A module's own edit page owns the title, form, summary, and actions:

@model RecordEditViewModel

<zone Name="Title">
    <breadcrumb name="RecordsEdit" title="@T["Edit {0}", Model.Name]">
        <breadcrumb-item id="Records" action="Index" controller="Record" area="My.Module">@T["Records"]</breadcrumb-item>
    </breadcrumb>
</zone>

<div asp-validation-summary="ModelOnly"></div>

<form asp-action="Edit" asp-route-returnUrl="@ViewData["ReturnUrl"]" method="post" class="no-multisubmit">
    <div class="ocat-wrapper" asp-validation-class-for="Name">
        <label asp-for="Name" class="ocat-label ocat-label-required">@T["Name"]</label>
        <div class="ocat-end">
            <input asp-for="Name" class="form-control" autofocus />
            <span asp-validation-for="Name"></span>
        </div>
    </div>

    <div class="action-bar-bottom">
        <a asp-action="Index" class="btn btn-secondary cancel" role="button">@T["Cancel"]</a>
        <a asp-action="Delete" asp-route-id="@Model.Id" class="btn btn-danger action-bar-secondary" role="button" data-url-af="UnsafeUrl RemoveUrl">@T["Delete"]</a>
        <button type="submit" class="btn btn-primary save">@T["Save"]</button>
    </div>
</form>

Edit Page Action Bar

Since Orchard Core 4.0 the submit buttons of admin edit pages (Publish, Save, Cancel, ...) render in a bar fixed to the bottom of the viewport, always visible without scrolling. TheAdmin pads the page so the bar never hides the end of the form.

<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" data-my-module-save>@T["OK"]</button>
</div>

Positions of the built-in content editor action shapes (Actions zone of Content.Edit):

| Shape | Button | Position |

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

| ContentPreview_Button | Preview | Actions:5 |

| Content_DeleteButton | Delete | Actions:10 |

| Content_UnpublishButton | Unpublish | Actions:20 |

| ArchiveLaterPart_Edit | Archive Later | Actions:20.5 |

| PublishLaterPart_Edit | Publish Later | Actions:25 |

| Content_UserTaskButton | workflow user task actions | Actions:28 |

| Content_SaveDraftButton | Save Draft | Actions:30 |

| Content_PublishButton | Publish | Actions:40 |

Before Orchard Core 4.0 final, Publish was at Actions:10, Delete at Actions:40, Preview at Actions:after, Archive Later at Actions:10.5, Publish Later at Actions:10 and the user task buttons at Actions:30; placement rules that position a custom shape relative to these buttons need new positions (for example Actions:35 to sit between Save Draft and Publish).

A split button can remember the last action the user chose (for example Save vs Save and continue). Put these attributes on the btn-group, which contains one submit button and one dropdown-item submit button, both with an explicit value:

<div class="btn-group"
     role="group"
     aria-label="@T["Save actions"]"
     data-action-group="my-module-record-save-action"
     data-action-default="Save"
     data-label-default="@T["Save"]"
     data-action-alt="SaveAndContinue"
     data-label-alt="@T["Save and continue"]">
    <button type="submit" name="submit" value="Save" class="btn btn-primary save">@T["Save"]</button>
    <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
        <span class="visually-hidden">@T["Toggle Dropdown"]</span>
    </button>
    <div class="dropdown-menu">
        <button type="submit" name="submit" value="SaveAndContinue" class="dropdown-item save-continue">@T["and continue"]</button>
    </div>
</div>

data-action-group is the storage key (pages sharing a key share the choice); the choice is stored per tenant in the browser's admin preferences.

Restyling Admin Forms

The classes are the theming contract. A custom admin theme (see orchardcore-theme-creator) that depends on TheAdmin can turn every editor into a horizontal form with CSS only:

.ocat-wrapper,
.ocat-limited-wrapper {
    --ocat-gutter-x: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    margin-right: calc(-0.5 * var(--ocat-gutter-x));
    margin-left: calc(-0.5 * var(--ocat-gutter-x));
    margin-bottom: 1rem;
}

.ocat-wrapper > *,
.ocat-limited-wrapper > * {
    box-sizing: border-box;
    flex-shrink: 0;
    width: 100%;
    max-width: 100%;
    padding-right: calc(var(--ocat-gutter-x) * 0.5);
    padding-left: calc(var(--ocat-gutter-x) * 0.5);
}

.ocat-label { flex: 0 0 auto; width: 25%; padding-top: calc(0.375rem + var(--bs-border-width)); text-align: end; }
.ocat-start { flex: 0 0 auto; width: 25%; }
.ocat-end { flex: 0 0 auto; width: 75%; }
.ocat-end-offset { flex: 0 0 auto; width: 75%; margin-inline-start: 25%; }
.ocat-limited { flex: 0 0 auto; width: 33.333%; max-width: 33.333%; }

This works only because views follow the rules above: a row that skips ocat-end or mixes it with ocat-end-offset breaks the alignment.

Migrating Legacy Views

| Old markup | New markup |

|---|---|

| <div class="mb-3">, <div class="form-group">, @Orchard.GetWrapperClasses() | <div class="ocat-wrapper"> |

| <label class="form-label">, @Orchard.GetLabelClasses() | <label class="ocat-label"> |

| @Orchard.GetLabelClasses(inputRequired: true), label.input-required | ocat-label ocat-label-required |

| Control directly in the row, @Orchard.GetEndClasses() | Wrap in <div class="ocat-end"> |

| @Orchard.GetEndClasses(true), @Orchard.GetOffsetClasses(), checkbox rows | <div class="ocat-end-offset"> |

| @Orchard.GetStartClasses() | ocat-start |

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

| @Orchard.GetPartWrapperClasses(...), @Orchard.GetFieldWrapperClasses(...) | Literal ocat-wrapper content-part-wrapper ... / ocat-wrapper field-wrapper ... |

| TheAdminThemeOptions, TheAdminTheme:StyleSettings | CSS overrides of the ocat-* classes in an admin theme |

| Hint directly in the row | Hint inside ocat-end / ocat-end-offset |

| Buttons in ocat-wrapper > ocat-end-offset, or a top card ... position-sticky action-bar | <div class="action-bar-bottom">, secondary actions with action-bar-secondary |

See references/admin-edit-views-examples.md for a complete part with its driver, part settings editor, site settings editor, and workflow activity editor.

Related Skills

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.