How can I (if possible) get to the ModelMetadata from a view without creating a custom template for the given Model’s property?
Traditionally, I have just made a new template and altered the template using the ViewData.ModelMetadata.IsRequired (for example). However, I’m looking for how to access this information in the base view and not within a specific editor template.
In terms of why I don’t want to go the editor template route – I have a form where I need better control to the markup in terms of attributes on the input elements. EditorTemplates work decent but having a specialized template and ensuring additional ViewData are set to fulfill the attribute values isn’t clean in my opinion.
This should give you access:
You may checkout how the default templates are implemented. It might give you some additional ideas.