I am trying to use a modified MetadataProvider based on the CachedDataAnnotationsModelMetadataProvider. Within my custom metadata, I provide data into the additional values dictionary. When I look at the cache from within the provider, it is populated correctly with ModelMetadata objects and those objects are properly populated with the additional values.
Within my custom provider, I am overriding:
CreateMetadataPrototype(IEnumerable<Attribute> attributes, Type containerType, Type modelType, string propertyName)
and I am setting values within the provider through the add method on the dictionary.
However, when I access the ModelMetadata from a View, the additional data is no longer populated.
Other properties in the ModelMetadata are populated, but the additional data dictionary is not.
If I switch the custom metadataprovider to use the standard DataAnnotations metadata provider instead of the caching provider, the additional values are properly populated.
When I drill down into the MVC code, it appears as though the method
CachedDataAnnotationsModelMetadata CreateMetadataFromPrototype(CachedDataAnnotationsModelMetadata prototype, Func<object> modelAccessor)
does not fully populate the return CachedDataAnnotationsModelMetadata object.
I fix this by overriding the method, but this seems a bit strange and leads me to believe I am using the Cached provider incorrectly.
So is there a different prefered way to handle ModelMetadata in the cached provider?
use
CreateMetadataFromPrototype()insted ofCreateMetadataPrototype()