using System.Globalization; using Elternbeirat.Web.Services; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Http; namespace Elternbeirat.Web.Features.Posts; public partial class PostDetail { private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE"); [Parameter] public string Slug { get; set; } = ""; private Post? _post; protected override void OnParametersSet() { _post = PostService.Find(Slug); // Unknown slug -> 404, so UseStatusCodePagesWithReExecute serves the // /not-found page instead of an empty 200 response. if (_post is null && HttpContext is not null) { HttpContext.Response.StatusCode = StatusCodes.Status404NotFound; } } [CascadingParameter] private HttpContext? HttpContext { get; set; } }