Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6533945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:11:28+00:00 2026-05-25T10:11:28+00:00

I want to add a [Required] attribute to my DateTime editor template so that

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:11:28+00:00Added an answer on May 25, 2026 at 10:11 am

    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:

    public class MyViewModel
    {
        [Required]
        public string Foo { get; set; }
    }
    

    would assign:

    @{
        var isRequired = ViewData.ModelMetadata.IsRequired;
    }
    

    in the corresponding editor/display template.

    And if you had a custom attribute:

    public class MyCustomStuffAttribute : Attribute, IMetadataAware
    {
        public void OnMetadataCreated(ModelMetadata metadata)
        {
            metadata.AdditionalValues["customStuff"] = "some very custom stuff";
        }
    }
    

    and a view model decorated with it:

    public class MyViewModel
    {
        [MyCustomStuff]
        public string Foo { get; set; }
    }
    

    in the corresponding editor/display template you could fetch this:

    @{
        var myCustomStuff = ViewData.ModelMetadata.AdditionalValues["customStuff"];
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a non-required Moose attribute that can be set only
I have a list of string values that I want add to a hashtable
I want to add a property to my User model that returns the number
I'd like to add an attribute to products, and I want to do this
Basically I have an image in my application that I want to add hover
In HTML5, you can add the attribute draggable to any element -- it works
Do anyone know how I can add the following to form_alter? Currently I've got
I would like to replace validation message for all model properties that have [Required]
I have dbml with single table users i want add partial class for User
I have a website built with ASP.NET (3.5) and want add some level of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.