C#C
C#2y ago
schwartzmj

Redirect after form POST Blazor Static

Am I not able to have a statically rendered Blazor @code block return a redirect? e.g.:

c#
@code {

    private sealed class InputModel
    {
        [Required]
        [MaxLength(50)] public string Name { get; set; } = "";
        [Required]
        [MaxLength(300)]
        public string Description { get; set; } = "";
    }

    [SupplyParameterFromForm] private InputModel Input { get; set; } = new();

    public async Task CreateWebsite()
    {
        try
        {
            var website = new Website
            {
                Name = Input.Name,
                Description = Input.Description
            };
            DbContext.Websites.Add(website);
            await DbContext.SaveChangesAsync();
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }

    }
}
Was this page helpful?