Path: redb/redb.Templates/templates/redb-blazor/Components/Pages/ProductEdit.razor Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Templates/templates/redb-blazor/Components/Pages/ProductEdit.razor ---- @page "/products/new" @page "/products/{Id:long}" @inject RedbWork Work @inject NavigationManager Navigation @(Id is null ? "New product" : "Edit product")

@(Id is null ? "New product" : "Edit product")

@if (notFound) {

Product @Id was not found. Back to the list

} else {
Cancel
} @code { [Parameter] public long? Id { get; set; } private ProductInput input = new(); private bool notFound; protected override async Task OnParametersSetAsync() { if (Id is null) return; var product = await Work.RunAsync(redb => redb.LoadAsync(Id.Value)); if (product is null) { notFound = true; return; } input = new ProductInput { Name = product.Name ?? string.Empty, Category = product.Props!.Category, Price = product.Props.Price, InStock = product.Props.InStock, Description = product.Props.Description, }; } private async Task SaveAsync() { await Work.RunAsync(async redb => { // Load, then change: with change tracking on, the save writes only the fields that // differ from what was loaded. var product = Id is null ? new RedbObject { Props = new Product() } : await redb.LoadAsync(Id.Value) ?? throw new InvalidOperationException($"Product {Id} not found."); product.Name = input.Name; product.Props!.Category = input.Category; product.Props.Price = input.Price; product.Props.InStock = input.InStock; product.Props.Description = input.Description; await redb.SaveAsync(product); }); Navigation.NavigateTo(""); } /// What the form edits. Validation lives here, not on the Props class. private sealed class ProductInput { [Required, StringLength(200)] public string Name { get; set; } = string.Empty; [Required, StringLength(100)] public string Category { get; set; } = string.Empty; [Range(0, 1_000_000)] public decimal Price { get; set; } public bool InStock { get; set; } [StringLength(2000)] public string? Description { get; set; } } }