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):
edit-entity-dialog-sample.razoredit-entity-dialog-sample.razor.cs
Target component and project files:
- The target
.razorand.razor.cs - Related project files: models, enums, lookups, services
Design and styling context (search the project — these are NOT in the SKILL.md folder):
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 contextux-tokens.css,ux-base.css,ux-components.css— read from the project'swwwrootfolder 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.
Assess The .razor.cs Before Writing
Use for: Edit or update entity dialogs in Blazor with MudBlazor
Do NOT use for: Full pages, search pages, add dialogs, or non-Blazor projects
This is a dialog: close or cancel through MudBlazor dialog APIs rather than navigation
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 data loading, model construction, or service calls).
If skeleton — scaffold the missing members modelled on the sample .razor.cs:
- Add
[Parameter]properties needed for the dialog (e.g. entity ID) - Add a model field or property matching the sample pattern
- Implement
OnInitializedAsync()orOnParametersSetAsync()to load the entity via the appropriate service (search the project for a matching service interface) - Add
Save()/SaveAsync()that validates the form, calls the existing update service method, and closes the dialog withMudDialog.Close(DialogResult.Ok(true))on success - Add
Cancel()that only callsMudDialog.Cancel() - Add supporting methods only when they exist in the sample and the relevant service methods exist in the project
If implemented — preserve all existing logic exactly:
- Do NOT modify existing methods, service calls, or payload construction
- Do NOT add, rename, or remove model properties
- Do NOT rewrite existing C# functionality
Always forbidden (skeleton or implemented):
- Inventing service classes or interfaces that don't exist in the project
- Calling services directly from the
.razorfile - Adding navigation logic to the dialog flow
- Putting C# logic in
.razorusing@code
1. Dialog Structure And Data Loading
This component is a MudBlazor dialog, not a page.
Dialog rules:
- In
.razor.cs, useIMudDialogInstance - In
.razor, useTitleContent,DialogContent, andDialogActions - Do not use old dialog tags such as
MudDialogTitle,MudDialogContent, orMudDialogActions - For success, close with
MudDialog.Close(DialogResult.Ok(true)) - For cancel, use
MudDialog.Cancel()
Data loading:
- Receive dialog input through
[Parameter]properties — add them if absent in a skeleton - If an ID is passed, load the entity via the appropriate service method (implement
OnInitializedAsync()if it is an empty stub) - If a model is passed, prepopulate from that input structure
2. Save And Cancel Methods
Save() or SaveAsync() — add if absent in a skeleton:
- Validate the form
- Call the existing update service method without modification
- On success, close the dialog with a success result
- On error, keep the dialog open and set existing error state such as
serviceErrors.*
Cancel() — add if absent in a skeleton:
- Only cancel or close the dialog
- Do not reset model state
- Do not call services
Template bindings:
- Bind Save button to
Save()orSaveAsync() - Bind Cancel button to
Cancel() - Do not call backend methods directly from the Razor template
3. Form Validation
Use valid Blazor EditForm patterns with the project's existing validation approach.
Required fields must have:
- Existing validation annotations or validator wiring
- Visible validation messages
- No service call when invalid
Save button state:
- Disable Save when the form is invalid
- Disable Save while saving
4. Control Mapping
| Property Type | Control |
|---------------|---------|
| String | MudTextField |
| Boolean | MudSwitch or MudCheckBox |
| Enum | MudSelect with verified numeric values |
| Lookup | MudSelect from real option sources only |
| Array | Repeatable MudBlazor blocks |
| Date | MudDatePicker |
MudBlazor rules:
- Declare
Texplicitly for generic controls when required - Add placeholders to
MudSelect - Every
MudDatePickermust includePlaceholder="Select date" - If using
ValueChanged, pair it withValuerather than@bind-Value - Never assume enum members from sample code
5. Child Collections
- Add collection buttons only when matching backing methods exist
- Remove collection buttons only when matching backing methods exist
- In
forloops, usevar index = i;and never bind directly toi
6. Styling
- Prefer shared utilities first
- Keep component-specific styles minimal
- Never modify existing shared styles or theme values
- Match the sample dialog layout closely
- Cancel button in DialogActions must use
Variant="Variant.Outlined"Color="Color.Secondary" - Save button must use
Variant="Variant.Filled"Color="Color.Primary"withDisabledbound to the saving flag
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
- [ ] All bindings used in
.razorresolve to members in.razor.cs(including any members just scaffolded) - [ ] No
@codeblock was introduced in.razor - [ ] Dialog uses
IMudDialogInstanceand modern MudBlazor dialog sections - [ ] Entity data is loaded or prepopulated through lifecycle or backing methods (implemented or added if the skeleton had none)
- [ ] Save closes with
DialogResult.Ok(true)on success - [ ] Cancel only cancels the dialog
- [ ] Existing update service methods were not modified
- [ ] Model properties were not arbitrarily renamed or removed — additions are allowed only when scaffolding a skeleton
- [ ] No service classes or interfaces were invented that don't exist in the project
- [ ] Enum options were verified against the real enum definition
- [ ] Every
MudDatePickerincludesPlaceholder="Select date" - [ ] Validation prevents service calls when invalid
- [ ] Shared styles were preserved and component styling remained minimal