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
Post a Comment