Skip to content

Components

Zach Sanford edited this page Nov 4, 2022 · 3 revisions

πŸ” Overview

One of the benefits of using .NET's Blazor Server (and Blazor WASM for that matter) is the use of components. Components are reusable chunks of code that can be called in one line. They also can accept arguments in the form of parameters.

πŸ“¦ Modal

File
~\Staffify\Components\Modal.razor

I created the modal component because it might be used more as the application grows. As of right now, I use it to give the user a confirmation that their changes were made when they update an employee record. It then redirects you back to the index page after confirmation. The component accepts four parameters.

[Parameter]
public string Title { get; set; } = "Modal Title";
[Parameter]
public string Body { get; set; } = "Modal Body Text";
[Parameter]
public string ButtonText { get; set; } = "Close";
[Parameter]
public string Route { get; set; } = "/";

These parameters also contain defaults so I can call the component on a web page without explicitly adding parameters. Here I use it in the Employee Details page.

<Modal Title="Update Details" Body="The employee has been successfully updated" ButtonText="Close" Route="/" />

modal

Staffify Wiki

  • πŸ§‘β€πŸ€β€πŸ§‘ Models

Clone this wiki locally