Methods and Statements

Methods are the bread and butter of every Blazor application. You use them to query a database, respond to user actions, handle Blazor lifecycle events and more.

You can manage methods and their statements of your Blazor components or C# classes via Radzen Blazor Studio’s Methods design mode.

To access Methods design mode open a .razor or .cs file and click the corresponding button in the design canvas toolbar.

Radzen Blazor Studio will display a dropdown with all methods that are accessible are accessible from the current class / component.

Radzen Blazor Studio lists methods that may be defined in other files (when you use partial classes for example).

Methods consist of statements - basically one or more lines of code that perform certain task. For example assignments, loops, if checks, try/catch blocks, method invocations et. al.

Radzen Blazor Studio allows you to visually edit a method by adding or removing statements to it.

Invoke a method and assign its result to a field

Invoking a service method and assigning its result to a field is a common task in Blazor development. Here is how to do it with Radzen Blazor Studio.

  1. Open a .razor file and enter Methods design mode.
  2. Pick OnInitializedAsync from the Override dropdown. It lists all Blazor lifecycle methods which are not yet overridden by your component.
  3. Click the + button below the start box and pick Invoke from the popup.
  4. Select the Method you wish to invoke. Start typing its name and Radzen Blazor Studio will suggest you the available options - all methods of the injected services as well as the own methods of the current file.
  5. If the chosen method returns a value you can set Result as well. You can either pick an existing field or property to assign the result to or create a new one.

Invoke a method

Supported statements

Radzen Blazor Studio provides built-in support for the following statements.

Assignment

Assign values to existing fields, properties or variables.

Declaration

Declare method variables to store method or computation results.

If

Create C# if statements.

Switch

Create C# switch statements.

For

Create C# for loops.

ForEach

Create C# foreach loops.

Do/While

Create C# do/while loops.

While

Create C# while loops.

Invoke

Invoke own methods or methods of properties or fields.

Use the NavigationManager to navigate to a page. A page is a Blazor component with a @page directive.

Return to the previous page.

Try/Catch

Create a try/catch block.

Using

Create a C# using statement.

Notify

Display a notification message. Uses the Radzen.Blazor library’s NotificationService.

Open Dialog

Display a dialog. Uses the Radzen.Blazor library’s DialogService.

Close Dialog

Closes the current dialog. Uses the Radzen.Blazor library’s DialogService.

Open Context Menu

Opens a context menu. Uses the Radzen.Blazor library’s ContextMenuService.

Show Tooltip

Opens a tooltip. Uses the Radzen.Blazor library’s TooltipService.

Execute

Any other C# statement.

Important: statements that require the Radzen.Blazor component library are available only in applications that have Radzen.Blazor correctly installed and the required services registered.