asp.net mvc - in mvc [required]attribute errormessages for string variable alone im getting customerrormessges but not for bool ,datetime,int -


my code like

public class user {      [required(errormessage = "please enter username")]     public string username { get; set; } 

for string property im getting error message properly. but...

    [required(errormessage = "please enter dateof birth")]     public datetime dob { get; set; } 

for im getting default model state validator message im getting like:

"required property 'datetime' not found in json. path '', line 5, position 2".

i want here "please enter dateof birth" .message im unable ..for bool or datetime or int im unble can on .thanks in advance

i going take guess trying assign null dob. datetime not nullable, can allow nulls changing follows:

[required(errormessage = "please enter dateof birth")] public datetime? dob { get; set; } 

this works int? , bool? too


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -