Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

ValidationSummary not displaying inside component

$
0
0

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.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>