I have a Register form that I had working perfectly in a RazorPages App that I am unable to get working in a similar form in a Blazor Application. In both applications, I took the basic User Registration form and added a SelectList for Organisations with Id as the Value and Name as the text.
I put both applications in a common solution and got the data for the SelectList from a Persistence layer/project as follows:
In the Razor Pages app, I generated the SelectList as follows:
public async Task OnGetAsync(string returnUrl = null) { ReturnUrl = returnUrl; var mhas = await _organisationService.GetMhasList(); ViewData["SelectListMhas"] = new SelectList(mhas, "Id", "Name"); }In the blazor app, data retrieval looked as follows:
public SelectList? SelectListMhas { get; set; }protected override async Task OnInitializedAsync(){ var mhas = await OrganisationService.GetMhasList(); SelectListMhas = new SelectList(mhas, nameof(OrganisationInListDto.Id), nameof(OrganisationInListDto.Name));}Both worked perfectly generating the required SelectList
For the Razor Pages app, the required field was coded as follows:
<div class="form-floating mb-3 "><select asp-for="Input.OrganisationId" asp-items="ViewBag.SelectListMhas" class="form-select"></select><label asp-for="Input.OrganisationId"></label><span asp-validation-for="Input.OrganisationId" class="text-danger"></span></div>This worked perfectly and a dropdown list organisations was produced when clicking on the field.
The equivalent code in the blazor app was as follows:
<div class="form-floating mb-3 "><label asp-for="Input.OrganisationId"></label><select asp-for="Input.OrganisationId" asp-items="SelectListMhas" class="form-select"></select><span asp-validation-for="Input.OrganisationId" class="text-danger"></span></div>This did not work. An empty dropdown list was produced when clicking on the field.
Any help greatly appreciated.
I have also tried using asp-items="@SelectListMhas" but this also did not work.