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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -