Blazor page adding entity

From IntentArchitect/Intent.Modules.NET · View interactive version

Blazor page adding entity is an AI agent skill from the GitHub repository IntentArchitect/Intent.Modules.NET. Implements Blazor add or create entity pages using MudBlazor forms, preserving existing .razor.cs service and navigation behavior while wiring a valid save flow and model-bound UI. Use when creating or implementing add, create, new, insert, or register entity pages in Blazor, including when an empty

How to use this skill

Skill file

MANDATORY: Read Samples Before Implementation

STOP — you MUST read ALL of the following before writing ANY code:

Samples (in the SAME folder as this SKILL.md):

  1. add-entity-sample.razor
  2. add-entity-sample.razor.cs

Target component and project files:

  1. The target .razor and .razor.cs
  2. Related project files: models, enums, lookups, services

Design and styling context (search the project — these are NOT in the SKILL.md folder):

  1. design.md — search for this file anywhere in the project; read it in full if found; if absent, note the absence and continue without design context
  2. ux-tokens.css, ux-base.css, ux-components.css — read from the project's wwwroot folder if present; note any that are absent

If any sample file (items 1–2) cannot be accessed: stop immediately, confirm the SKILL.md folder location, retry from that location, and if still inaccessible report which file is missing. Do not proceed with partial implementation or approximation.

If items 5–6 are not found: note the absence and continue — they are reference context, not blocking.


MANDATORY: Match Sample Layout (Visual Structure)

When a sample exists, you MUST match the sample's visual structure, not only its data behavior.

Required process:

  1. Reuse the sample's top-level component layout (hero header + main card) unless the user explicitly requests otherwise.
  2. If the sample uses shared utility classes (e.g. ux-fade-in-up, ux-gradient-primary), verify they exist by grepping for the class name as a substring across all CSS files under wwwroot (including ux-tokens.css, ux-base.css, and ux-components.css). CSS utility classes are often defined as compound selectors, so search for the class name alone. If the class name appears anywhere in any CSS file, it exists and must be used.

Forbidden:


Assess The .razor.cs Before Writing

Use for: Add or create entity pages in Blazor with MudBlazor

Do NOT use for: Search or list pages, edit forms, dialogs, or non-Blazor projects

Read the existing .razor.cs in full. Determine whether it is a skeleton (constructor, injections, and empty or stub methods only) or implemented (contains real model construction, service calls, or save logic).

If skeleton — scaffold the missing members modelled on the sample .razor.cs:

If implemented — preserve all existing logic exactly:

Always forbidden (skeleton or implemented):


1. Form: Build From The Model

Bind inputs only to properties that exist on model — adding the model field first if it does not yet exist in the skeleton.

Nullable objects:


2. Map Properties to MudBlazor Controls

| Property Type | Control |

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

| String | MudTextField or MudTextField Lines="..." |

| Boolean | MudSwitch or MudCheckBox |

| Enum | MudSelect with explicit numeric values |

| Lookup | MudSelect using real service-loaded options only |

| Array | Repeatable MudBlazor blocks |

| Date | MudDatePicker |

Enum rules:

  1. Locate the enum definition from imports or project search
  2. Read the enum file and verify exact member names and values
  3. Use only verified enum members
  4. For MudSelect, prefer numeric values with explicit casts such as Value="@((int)AddressType.Delivery)"
  5. Never invent enum members from samples

MudBlazor rules:


3. Form Validation

Use valid Blazor form patterns with EditForm and the component's existing validation conventions.

Required fields must have:

Save button state:


4. Save Flow

The Save button must call Save() or SaveAsync(). If neither exists in .razor.cs, add it following the sample pattern.

That save flow must:

  1. Validate before saving
  2. Call the existing create service method without modifying it
  3. Navigate on success using an existing or added navigation method

Forbidden:


5. Child Collections

Render child collections in repeatable MudBlazor UI blocks.

Buttons:

For for loops:


6. Styling

Design and styling context

Apply the design token and CSS utility context from the files you read in the mandatory phase. Use var(--token) for all inline Style= attributes — never hardcode hex values. Verify utility classes (e.g. ux-fade-in-up, ux-gradient-primary) exist before applying. The design context informs styling choices only — it does not override layout structure.


Definition of Done

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.