I'm editing data in a .NET 9 SSR page after passing in an Id.
It works well except the value of the dropdownlist is ignored on page load. I'm hardcoding this now and it still doesn't select the item in the list.
I've also tried binding the InputSelect to a string property, the same issue occurs.
I've asked AI and searched for hours but nothing works. I tried a select instead of InputSelect with @bind and it does select the right value on load but when I post the form the value is then 0 not what the user selects.
How can I fix this in a SSR form without using InteractiveServer or WASM?
@page "/abc/edit"@inject NavigationManager NavigationManager@using System.ComponentModel.DataAnnotations@using System.Text@using System.Text.Encodings.Web@using Microsoft.AspNetCore.Identity@using Microsoft.AspNetCore.WebUtilities@inject UserManager<ApplicationUser> UserManager@inject IUserStore<ApplicationUser> UserStore@inject SignInManager<ApplicationUser> SignInManager@inject IEmailSender<ApplicationUser> EmailSender@inject NavigationManager NavigationManager@inject ICustomerRelatedRepository _customerRelatedRepo@inject EmailServiceV2 _emailServiceV2@attribute [Authorize(Roles = Roles.Admin)]<PageTitle>Edit Related Customer</PageTitle><h1>Edit Related Customer</h1><MessageComponent Message="@_message" MessageError="@_messageError" />@* <button class="btn btn-primary mt-2 btn-block" @onclick="AddRelation">Add Relation</button>*@<hr />@if (Input is null){<p>Loading...</p>}else{<div class="row"><div class="col-md-8 mb-2"><EditForm method="post" Model="Input" OnValidSubmit="UpdateApplicationUser" FormName="create" Enhance><DataAnnotationsValidator /><input type="hidden" name="Input.Id" value="@Input.Id" /><input type="hidden" name="Input.PrimaryCustomerId" value="@Input.PrimaryCustomerId" /><input type="hidden" name="isFirstLoad" value="@isFirstLoad" /><div class="form-floating mb-3"><InputText @bind-Value="Input.FirstName" id="firstname" class="form-control" placeholder="" /><label for="firstname" class="form-label">First Name</label><ValidationMessage For="() => Input.FirstName" class="text-danger" /></div><div class="form-floating mb-3"><InputText @bind-Value="Input.LastName" id="lastname" class="form-control" placeholder="" /><label for="lastname" class="form-label">Last Name</label><ValidationMessage For="() => Input.LastName" class="text-danger" /></div><div class="form-floating mb-3"><InputDate @bind-Value="Input.DOB" id="dob" class="form-control" placeholder="" /><label for="dob" class="form-label">DOB</label><ValidationMessage For="() => Input.DOB" class="text-danger" /></div><div class="form-floating mb-3"><InputSelect @bind-Value="@Input.PrimaryRelationId" id="primaryrelationid" class="form-select"><option value="0">Please Select...</option><option value="1">Grandchild</option><option value="2">Child</option><option value="3">Niece/Nephew</option><option value="4">Spouse/SO</option></InputSelect><label for="primaryrelationid" class="form-label">Relationship</label><ValidationMessage For="() => Input.PrimaryRelationId" class="text-danger" /></div><div class="form-floating mb-3"><InputTextArea rows="5" @bind-Value="Input.MedicalHistoryDetails" id="medicalhistorydetails" class="form-control" placeholder="" style="height: 100px" maxlength="2000"></InputTextArea><label for="medicalhistorydetails" class="form-label">Medical History Details</label><ValidationMessage For="() => Input.MedicalHistoryDetails" class="text-danger" /></div><button type="submit" class="btn btn-primary">Update Related Customer</button></EditForm></div></div>}@code { [SupplyParameterFromQuery] public int Id { get; set; } private IEnumerable<IdentityError>? identityErrors; private string _message { get; set; } private string _messageError { get; set; } [SupplyParameterFromForm] private InputModel? Input { get; set; } [SupplyParameterFromQuery] private string? ReturnUrl { get; set; } private bool isFirstLoad = true; private string? Message => identityErrors is null ? null : $"Error: {string.Join(", ", identityErrors.Select(error => error.Description))}"; protected override async Task OnInitializedAsync() { if (Input == null) { var user = await _customerRelatedRepo.GetAsync(Id); Input = new InputModel(); Input.FirstName = user.FirstName; Input.LastName = user.LastName; Input.DOB = user.DOB; //Input.PrimaryRelationId = user.PrimaryRelationId.Value; Input.PrimaryRelationId = 2; Input.MedicalHistoryDetails = user.MedicalHistoryDetails; } } private async Task UpdateApplicationUser() { var user = new CustomerRelatedModel(); user.Id = Id; user.PrimaryCustomerId = Input.PrimaryCustomerId; user.FirstName = Input.FirstName; user.LastName = Input.LastName; user.DOB = Input.DOB; //user.PrimaryRelationId = Input.PrimaryRelationId; user.MedicalHistoryDetails = Input.MedicalHistoryDetails; await _customerRelatedRepo.UpdateAsync(user); } private void AddRelation() { _message = "You've clicked. " + DateTime.Now; } private sealed class InputModel { public bool isFirstLoad { get; set; } = true; public int Id { get; set; } public int PrimaryCustomerId { get; set; } public DateTime AgreedToWaiverDate { get; set; } public bool HasMedicalHistory { get; set; } public string MedicalHistoryDetails { get; set; } = string.Empty; [Range(1, 4, ErrorMessage = "Please select relationship")] public int PrimaryRelationId { get; set; } [Required] [Display(Name = "First Name")] [MaxLength(50)] public string FirstName { get; set; } = ""; [Required] [Display(Name = "Last Name")] [MaxLength(50)] public string LastName { get; set; } = ""; [Required] public DateTime? DOB { get; set; } }}