c# - How to assign model validation error to a key -
in same way can add model validation within controller:
modelstate.addvalidationerror([key], "this error message")
can add error within model validation using annotations?
// demonstration purposes [required(errormessage = "this error message"), adderrormessagetokey = [key]] public string username { get; set; }
sometimes it's not appropriate add error message particular property. in application wish show 1 error message.
you can put helper every property in viewpage .
@html.validationmessage("customerror")
and in controller:
use tempdata in actionresult tempdata["customerror"] = "this error message";
Comments
Post a Comment