Get the App
SLTechnology News&Howtos  ›  Development  › 

How to bind Action parameters to Model in NopCommerce

Shulou Source: shulou.com Published: 2022-06-03 13:02:45 10月03日 Update

This article will explain in detail how to bind Action parameters to Model in NopCommerce. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Action parameters in asp.net MVC are not only basic types, but also support entity parameters. So how does the data from the client be mapped or transformed into entity objects? Is through the entity binding class ModelBinder. Before requesting to convert to the Action method of background Controller, this series of classes capture the passed data, parse and transform it, and finally become entity class objects.

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

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

NopModelBinder inherits DefaultModelBinder's entity binding class from the system, but seems to leave an interface instead of using it. It mainly inherits the methods of the parent class, with a slight change: 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 has added a filtering method, but this method has not been enabled.

The 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 subclasses have been found to implement this method.

This is the end of this article on "how to bind Action parameters in Model in NopCommerce". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Methods parameters entities just articles support objects not yet data more this method system good practical code content background place subclasses customers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MariaDB NVidia Shulou Technology Microsoft