I have a Base class for an Add/Edit form
public partial class BaseAddForm<TInput, TOutput> : ComponentBase where TInput : BaseModel, new() where TOutput: BaseModel, new()In this base I have the [Parameter]
[Parameter] public TInput Input { get; set; }In the drived class (which is using Blazorise compoents) I then bind as follows;
<Validation Validator="@ValidationRule.None"><Field Horizontal="true" ColumnSize="ColumnSize.Is6.OnDesktop"><FieldLabel ColumnSize="ColumnSize.Is3.OnDesktop">Group</FieldLabel><FieldBody ColumnSize="ColumnSize.Is9.OnDesktop"><TextEdit @ref="companyGroupTextBox" @bind-Text="@Input.Group" Placeholder="Enter the Company Group Name.."></TextEdit></FieldBody></Field>However, the field is appearring as blank when rendering (even though Input has values).
In the derived class .cs OnInitializedAsync() I have (redcued for brevity);
protected override async Task OnInitializedAsync() { Test = Input; if (Input.Address == null) { Input.Address = new CompanyAddressInputModel(); } if (Input.Contacts != null) { var primaryContact = Input.Contacts.FirstOrDefault(x => x.IsPrimaryContact); if (primaryContact != null) { InputMainContact = primaryContact; } } await RefreshBusinessTypesAsync(); await GetCompanyPositionsAsync(); await base.OnInitializedAsync(); }</Validation>If you note I have Test = Input as a test and if I then;
<Validation Validator="@ValidationRule.None"><Field Horizontal="true" ColumnSize="ColumnSize.Is6.OnDesktop"><FieldLabel ColumnSize="ColumnSize.Is3.OnDesktop">Group</FieldLabel><FieldBody ColumnSize="ColumnSize.Is9.OnDesktop"><TextEdit @ref="companyGroupTextBox" @bind-Text="@Test.Group" Placeholder="Enter the Company Group Name.."></TextEdit></FieldBody></Field></Validation>The Test.Group value appears?
For completness in the base class I have tried the following to trigger the chang ein state to update;
protected override async Task OnInitializedAsync(){ _isInitialized = true; await ResetAsync();}protected override async Task OnAfterRenderAsync(bool firstRender){ if (firstRender) { _isInitialized = true; await ResetAsync(); }}public void Dispose(){ _isInitialized = false;}public virtual async Task ResetAsync(){ try { if (InputModelPreSetData != null) { Input = InputModelPreSetData.DeepCopy(); } else { Input = new TInput(); } if (!renderHandle.IsInitialized) { //not intialised so return to avoid an error return; } if (FormValidations == null) { FormValidations = new Validations(); } else { await FormValidations.ClearAll(); } } catch(Exception ex) { _logger.LogError(ex, $"Error in ResetAsync '{ex.Message}'"); } finally { StateHasChanged(); }}Can anyone tell me why Blazor doesn't seem to be picking up the change in state on the base model parameter please?