I want to add a [Required] attribute to my DateTime editor template so that I can add the appropriate validation schemes or a DataType.Date attribute so I know when I should only display dates. But I can’t figure out how to get the metadata that says which attributes the Editor Template has assigned to it.
I want to add a [Required] attribute to my DateTime editor template so that
Share
The built-in attributes, such as
[Required]assign different properties on the metadata (see the blog post I have linked at the end of my answer to learn more). For example:would assign:
in the corresponding editor/display template.
And if you had a custom attribute:
and a view model decorated with it:
in the corresponding editor/display template you could fetch this:
Also you should absolutely read Brad Wilson’s series of blog posts about what ModelMetadata and templates in ASP.NET MVC is and how to use it.