I have a dialog that has a Contact component. I pass in a Contact object from the dialog as a parameter to the component. The component maps the Contact properties to a ContactModel. I have a ValidationSummary, but it doesn't display the messages. I verified that the EditContext is getting the ValidationMessageStore errors. After a bit of testing I have found that if you pass in any object, not just the model, then the ValidationSummary doesn't work. I changed it to passing a contactId and that works, but now I'm getting the contact twice.
Here's what I have:
//[Parameter]public Contact CurrentContact { get; set; } = new();[Parameter]public int ContactId { get; set; }private EditContext _editContext;private ValidationMessageStore? messageStore;protected override async Task OnParametersSetAsync(){ try { if (ContactId == 0) CurrentContact = new Contact(); else CurrentContact = await HttpHelper.GetObject<Contact>(state, $"contacts/contact/{ContactId}"); _editContext = new(_model); _model = UtilityMethods.MapTo<ContactModel>(CurrentContact); if (_model.ContactID == 0) _model.Active = true; _editContext = new(_model); _editContext.OnValidationRequested += OnValidationRequestedAsync; messageStore = new(_editContext); StateHasChanged(); } catch (Exception e) { await DialogService.AlertAsync(e.Message, "Contact"); }}This code works because I commented out the object parameter and just used an int. So how do I get the ValidationSummary to work while passing in an object?
Thank you.