Question

I am new to MVC, so please bear with me.

We have a large WebForms website, where content is managed by a custom CMS. I have added DataAnnotation attributes to my model properties. The attributes have an ErrorMessage property, but this must be a compile-time constant.

I would like to get error message texts at runtime from out custom CMS. We already do this in our WebForms pages, so the infrustructure is in place i.e. manager classes with aproprate methods for retrieving the correct texts by key.

My question is where do I hook in at runtime in order to populate the texts from the CMS to be displayed when validation error occur client-side or server-side?

Était-ce utile?

La solution

One way I guess would be to create your own DataAnnotationsModelMetadataProvider. Derive from this class and override the CreateMetadata method. Don't forget to register your custom MetaDataProvider with the ModelMetadataProviders when your WebApp initializes.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top