Aspnetcore: How can I retrieve all the ValidationMessageStore associated with a given field identifier

Created on 26 Apr 2020  路  6Comments  路  Source: dotnet/aspnetcore

I know how to retrieve the validation message via EditContext, but how to get a ValidationMessageStore, read its contained message, and apply some changes to it.

Thanks...

Answered Resolved area-blazor question

Most helpful comment

Alternatively, it's probably easier for you to mutate the way things are displayed as an aspect of rendering. For example, create your own custom <ValidationSummary> component that iterates over the messages, and does whatever you want to filter the list, display different text, etc.

All 6 comments

I'm curious, what do you want to achieve?

Just read their contents, manipulate their message text, perhaps apply some styles, and such like.

ValidationMessageStore is a way of flowing messages into the edit context. It's not a general collection that you can mutate arbitrarily from outside, because then the system would have no way to know when parts of it need to be regenerated, which of your changes are safe to overwrite, etc. The only code that can safely modify its contents is the code that creates it.

So if you want to have some centralised place to modify the messages that are being added, you'd need to implement that yourself.

If this becomes a common requirement we can certainly consider adding new APIs in this area in the future.

Alternatively, it's probably easier for you to mutate the way things are displayed as an aspect of rendering. For example, create your own custom <ValidationSummary> component that iterates over the messages, and does whatever you want to filter the list, display different text, etc.

Many thanks, maestro...I'll try both alternatives. The second is much easier and requires less knowledge of the internals.

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

Was this page helpful?
0 / 5 - 0 ratings