1. Clear Validation ModelValidated directly in the action in controller, eg:
[HttpPost]
Public Viewresult makebooking (Appointment appt) {
if (string. IsNullOrEmpty (appt. ClientName)) {
Modelstate.addmodelerror ("ClientName", "Please enter your name");
}
if (Modelstate.isvalidfield ("Date") && datetime.now > Appt. Date) {
Modelstate.addmodelerror ("date", "Please enter a date in the future");
}
if (!appt. termsaccepted) {
Modelstate.addmodelerror ("termsaccepted", "you must accept the terms");
}
if (modelstate.isvalid) {
Repository. Saveappointment (appt);
Return View ("Completed", appt);
} else {
return View ();
}
}
If validation does not pass, an error is done. The style of the error is defined in the input-validation-error of the ~/content/site.css file, which defaults to the following:
. input-validation-error {
border:1px solid #ff0000;
Background-color: #ffeeee;
}
The above wording just does not pass the verification, but does not give the error message, if wants to display the error message, must add in the view: @Html. ValidationSummary ()
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.