Annotation [Required] for the DateTime in class model

sblb 1,231 Reputation points
2022-09-29T14:18:19.927+00:00

Hi,

I want to put the data annotation for the DateTime but it is not taken into account

[Required]  
public DateTime DateCrea { get; set; }  

i.e. in my application if I don't enter a value I can validate my page (e.g. creation).
Do you have any idea where the problem comes from? Should I add something specific for the DateTime?

Thanks in advance

Developer technologies | .NET | Blazor
{count} votes

2 answers

Sort by: Most helpful
  1. sblb 1,231 Reputation points
    2022-09-29T15:42:15.46+00:00

    Are you asking about an Entity Framework class model

    yes

    A View model in your Blazor application?

    yes

    Model binding in Web API?

    no

    Is DateCrea a column in a table ... are you expecting a required user message in a Blazor application?

    yes, I expect a message, so the user must fill in the DateCrea field.


  2. Bruce (SqlWork.com) 78,086 Reputation points Volunteer Moderator
    2022-09-29T15:57:35.753+00:00

    show your form. as a date time is not nullable, its required by default.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.