c# - Data annotation throw exception instead of validation message -


in asp mvc use data annotation

[stringlength(500)] public string comment { get; set; } 

and in controller :

public actionresult applyvacation(request request , formcollection form) {     if (modelstate.isvalid)     {         return view("success");     } } 

in view use :

@html.validationmessagefor(model => model.comment, "", new { @class = "text-danger" }) 

and when enter value excced 500 string length throw exception instead of validation message exception :

system.data.entity.validation.dbentityvalidationexception: validation failed 1 or more entities.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -