of 5 Model Binding Action Parameters of NopCommerce Architecture Analysis

  • 2021-07-16 02:15:52
  • OfStack

The Action parameters in asp. net MVC are not only basic types, but also support entity parameters. So how does the data coming from the client map or transform into entity objects? Is through the entity binding class ModelBinder. Before the request is converted to the Action method of the background Controller, this series of classes captures the passed data, parses and converts it, and finally becomes an entity class object.

Before the system starts, the method Application_Start in Global. asax. cs calls the following code to define parameter conversion rules.


//model binders 
ModelBinders.Binders.Add(typeof(BaseNopModel), new NopModelBinder()); 

NopModelBinder inherits DefaultModelBinder to assume the entity binding class of the system, but it seems that only one interface is left and not used. Mainly inherits the method of the parent class, but the slight change is that the method BindModel adds binding support for NopModel.


public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) 
{ 
 var model = base.BindModel(controllerContext, bindingContext); 
 if (model is BaseNopModel) ((BaseNopModel) model).BindModel(controllerContext, bindingContext); 
 return model; 
}

Method GetModelProperties adds a filtering method, but this method has not been enabled.

Class BaseNopModel is the base class for all Model and supports the storage of custom attributes. And there is a method BindModel bound to the parser, but no subclass has been found to implement this method.


Related articles: