ASP. net mvc Model verification (3)

Source: Internet
Author: User

ASP. net mvc Model verification (3)
Preface in the previous article, we talked about where the default Model verification is in the MVC Framework and the internal execution of the DefaultModelBinder type, we can see the specific method in which the default Model verification is executed. The topic of this article is to simulate the default implementation. The custom Model binder inherits from the DefaultModelBinder type, and rewrite some important methods. Model Verification simple use example ModelValidator use the custom defamodelmodelbinder of the generation process to verify the custom ModelValidatorProvider and ModelValidator ValidationAttribute feature class use the sample of the custom ValidationAttribute class to implement the custom defamodelmodelbinder for verification the following example is used to modify data from ASP. net mvc Model verification (1) Example in length. I will not talk about it here, so I will directly paste the code. The first is the definition of ViewModel, code 1-1. Code 1-1 copy the namespace MvcApplication code. models {public class RegistrationInformation {public string ID {get; set;} public string UserID {get; set;} public string Password1 {get; set;} public string Password2 {get; set ;}public string Name {get; set ;}} copy the Definition of the code controller, code 1-2: code 1-2 copy the code public class ModelValidatorController: controller {public ActionResult Index () {return View (new Models. reg IstrationInformation ();} public ActionResult ModelValidator (RegistrationInformation regInfo) {return View (regInfo) ;}} copy the View definition corresponding to the Code Controller method, code 1-3: code 1-3-1 Index view copy code @ model MvcApplication. models. registrationInformation @ {ViewBag. title = "Index" ;}< h2> Index

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.