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 Label parameter, else the method name (Method).
  • Hidden — when the user lacks permission (DataGraphContext.IsMethodAllowed is false), nothing renders.
  • Disabled — when the server's DisableIf marks the method disabled for this record (carried on RecordReadOnly); 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