1.MVC Self-band check
Create a new User entity class
public class Users {public int Id {get; set;} [Stringlength (5,errormessage = "* Length must be <5")] [Required (errormessage = "* Name required")] public string UserName {get; set;} [RegularExpression (@ "^\d+$")] [Range (18,100)] [Required (errormessage = "*")] public int age{get; set;} }
New controller users and create mandatory type views with the creation template
Public ActionResult Index () { return View (); } Public ActionResult Add () { return View (); } [HttpPost] Public ActionResult Add (user user) { if (modelstate.isvalid) { //modelstate.isvalid = True checksum successful } Return redirecttoaction ("Index"); }
Front Page view requires these 3 JS support
<script src= "~/scripts/jquery-1.8.2.min.js" ></script> <script src= "~/scripts/ Jquery.validate.min.js "></script> <script src=" ~/scripts/jquery.validate.unobtrusive.min.js " ></script>
2. Global client (server side) check on or off
In the Web. config configuration
<appSettings> <add key= "webpages:enabled" value= "false"/> <add key= "enableclientvalidation "Value=" true "/>//global client check on <add key=" Enableunobtrusivejavascript "value=" true "/>//global service-side checksum open </appSettings>
On a page.
@{ html.enableclientvalidation (FALSE);//Current page client validation off Html.enableunobtrusivejavascript (false);// Current server-side validation off }
Record learning MVC process, MVC validation (iv)