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