First of all, in general, the validation of a property may require more than one remote authentication, for example, for the user name, we need to make some restrictions on its length, which can be solved by the stringlength feature, and also need to verify that the user name cannot be duplicated. This needs to be solved by the remote feature.
Now you need to add another validation, that is, the user name cannot contain forbidden words. The forbidden word is saved in the database. At first I think this is simple, and then add a remote verification does not solve the originalThe
same attribute is not supported with two remote authentication。 What to do at this time, try to write two verification in the same remote, but this can only show a errormessage, is rejected. (I thought the method of the remote attribute could only return a bool value and not return errormessage). In fact
remote verification can also customize ErrorMessage, I suddenly realized that I had always thought that I could only return
true or FalseOf If you do not return a bool value when validating to False, you can return errormessage directly. Here's how:
Public Jsonresult Checkusername (StringUserName) {if (Isuniquename (userName) && Isforbiddenname (userName)) {return Json (true, Jsonrequestbehavior.allowget); } else if (! Isuniquename (userName) {return Json ( " user name is not unique! "else {return Json ( Span style= "color: #800000;" > " username does not contain forbidden words! "
This will perfectly solve the problem of requiring multiple remote authentication.
Mvc-model data Annotations (iii) a consideration for-remote validation