The ASP.NET Core framework uses a model metadata provider to extract information from the model. This metadata provider can be accessed through MetadataProperty of Html and is exposed as IModelMetadataProvider. By default, it is set to an instance of DefaultModelMetadataProvider, which can be changed through the dependency injection framework, and its contract defines only two relevant methods:
- GetMetadataForType (ModelMetadata): Returns metadata for the model type itself
- GetMetadataForProperties (IEnumerable<ModelMetadata>): Metadata for all of the public model properties
You never normally call these methods; they are called internally by the framework. The ModelMetadata class they return (which may actually be of a derived class, such as DefaultModelMetadata) is what should interest us more. This metadata returns the following:
- The display name and description of the type or property...