Method Buttons
Summary
A server [Method] becomes a button with no wiring — MethodButton reads the method's metadata from the data graph and renders, hides, or disables itself accordingly.
<MethodButton Method="ApplySurcharge" DataSet="@dataSet" Label="Apply surcharge" />
From [Method] to button
graph LR
M["server [Method]<br/>+ DisableIf"] --> E["/api/entitymetadata<br/>+ RecordReadOnly"]
E --> G["client data graph"]
G --> B["MethodButton<br/>label · hide · disable"]
The graph drives three things:
- Label — the
Labelparameter, else the method name (Method). - Hidden — when the user lacks permission (
DataGraphContext.IsMethodAllowedis false), nothing renders. - Disabled — when the server's
DisableIfmarks the method disabled for this record (carried onRecordReadOnly); updates live as the record changes.
Place the button inside a DataGraph, which supplies the cascading context.
Invoke, or handle the click yourself
| Mode | Set | Behaviour |
|---|---|---|
| Auto-invoke | DataSet |
Click POSTs the method via InvokeMethodAsync; the graph refreshes if the result is the root entity. Add Body for a payload, OnInvoked for the response. |
| Manual | OnClick |
You handle the click — use for Read methods (GET) or custom flows. OnClick wins if both are set. |
@* Modify method — auto POST and refresh *@
<MethodButton Method="ApplySurcharge" DataSet="@dataSet" OnInvoked="OnApplied" />
@* Read method — manual GET *@
<MethodButton Method="PreviewSurcharge" OnClick="PreviewAsync" Variant="Variant.Outlined" />
Custom content
Supply ChildContent to replace the default MudButton; it still respects the permission gate.
<MethodButton Method="Approve">
<MudButton Color="Color.Success" OnClick="HandleApprove">Approve invoice</MudButton>
</MethodButton>
Disabled, Class, Variant, and Color pass through to the default button.
See also
- Disable a Method — server-side
DisableIfgreys the button. - Methods — declaring and implementing methods.
- PropertyComponent & PropertyGroup