# Radzen Blazor Components ## Overview Radzen Blazor Components is a free, open-source library of 90+ Blazor components including DataGrid, Scheduler, Chart, Form, Dialog, and Notification. The library provides its own design system with multiple built-in themes (Material, Standard, Dark, Humanistic) and does not depend on Bootstrap or other CSS frameworks. Radzen components support Blazor Server, Blazor WebAssembly, and .NET 8+ SSR with per-component interactivity. The optional Radzen IDE provides visual CRUD page generation, but the component library works standalone via NuGet. ## Installation and Service Registration Install the `Radzen.Blazor` NuGet package and register services in `Program.cs`. ```csharp using Radzen; var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); // Register Radzen services builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); var app = builder.Build(); app.UseStaticFiles(); app.UseAntiforgery(); app.MapRazorComponents() .AddInteractiveServerRenderMode(); app.Run(); ``` ## DataGrid with Server-Side Loading The `RadzenDataGrid` component provides sorting, filtering, grouping, and virtual scrolling. Use `LoadData` for server-side operations. ```csharp @page "/invoices" @using Radzen @using Radzen.Blazor @inject IInvoiceService InvoiceService @code { private RadzenDataGrid _grid = null!; private IEnumerable? _invoices; private int _count; private async Task OnLoadData(LoadDataArgs args) { var result = await InvoiceService.GetPagedAsync( filter: args.Filter, orderBy: args.OrderBy, skip: args.Skip ?? 0, top: args.Top ?? 20); _invoices = result.Items; _count = result.TotalCount; } private BadgeStyle GetBadgeStyle(string status) => status switch { "Paid" => BadgeStyle.Success, "Overdue" => BadgeStyle.Danger, "Pending" => BadgeStyle.Warning, _ => BadgeStyle.Light }; private void EditInvoice(Invoice invoice) { /* navigation logic */ } private void DeleteInvoice(Invoice invoice) { /* delete with confirmation */ } } ``` ## Forms with Validation Radzen provides form components with built-in validators that render inline error messages. ```csharp @page "/contacts/new" @using Radzen @using Radzen.Blazor @inject NavigationManager Navigation @inject IContactService ContactService @inject NotificationService NotificationService @code { private ContactModel _model = new(); private readonly List _categories = new() { "Client", "Vendor", "Partner", "Internal" }; private async Task HandleSubmit() { await ContactService.CreateAsync(_model); NotificationService.Notify(NotificationSeverity.Success, "Saved", "Contact created."); Navigation.NavigateTo("/contacts"); } public class ContactModel { public string FullName { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; public string Phone { get; set; } = string.Empty; public string Category { get; set; } = string.Empty; } } ``` ## Dialog Service Use `DialogService` to open components as modal dialogs and receive results. ```csharp @inject DialogService DialogService // Open a component as a dialog private async Task OpenEditDialog(Invoice invoice) { var result = await DialogService.OpenAsync( "Edit Invoice", new Dictionary { { "Invoice", invoice } }, new DialogOptions { Width = "600px", Height = "500px", Resizable = true, Draggable = true, CloseDialogOnOverlayClick = false }); if (result is true) { await _grid.Reload(); } } ``` ## Radzen vs Other Free Blazor Libraries | Feature | Radzen | MudBlazor | Blazorise (free) | Ant Design Blazor | |---|---|---|---|---| | Component count | 90+ | 60+ | 50+ (free tier) | 60+ | | Built-in themes | 5 | 3 | Via provider | 1 | | DataGrid | Full-featured | Full-featured | Basic | Full-featured | | Scheduler | Yes | No | No | No | | Dialog service | Yes | Yes | Yes | Yes | | Form validators | Component-based | EditForm-based | Component-based | EditForm-based | | Visual IDE | Radzen IDE (optional) | No | No | No | ## Best Practices 1. **Use `LoadData` with `LoadDataArgs.Filter` and `LoadDataArgs.OrderBy` for all DataGrids displaying server-sourced data** and translate the OData-style filter string to your data layer using `System.Linq.Dynamic.Core`, avoiding loading the full dataset into memory just to support client-side filtering. 2. **Register `DialogService`, `NotificationService`, `TooltipService`, and `ContextMenuService` as `Scoped` in `Program.cs`** and add the corresponding ``, ``, ``, and `` components in `MainLayout.razor`, not in individual pages; missing these root components causes silent failures when services are injected. 3. **Use `RadzenTemplateForm` with component-specific validators (`RadzenRequiredValidator`, `RadzenEmailValidator`)** rather than `EditForm` with `DataAnnotationsValidator`, because Radzen's validators render inline within `RadzenFormField` helper slots and integrate with the Radzen theme; mixing `EditForm` and Radzen components produces misaligned validation messages. 4. **Set explicit `Width` on each `RadzenDataGridColumn` for fixed-content columns** (IDs, dates, status badges, action buttons) and leave one primary text column without width to fill remaining space, preventing horizontal scrollbar appearance and content overflow on narrow viewports. 5. **Use `FormatString` on `RadzenDataGridColumn` for date and numeric formatting** (e.g., `"{0:C2}"`, `"{0:d}"`) instead of a `