Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

argument for custom model binder MVC

For the code below, I am wondering how Employee type affects by prefixed [] brackets

public ActionResult SaveEmployee([ModelBinder(typeof(MyEmployeeModelBinder))]Employee e, string BtnSubmit)
{
        // some logic
}
like image 922
nicholas Avatar asked Dec 14 '25 17:12

nicholas


1 Answers

MyEmployeeModelBinder is a custom model binder, that will execute instead of default model binder in Employee e.

public class MyEmployeeModelBinder: DefaultModelBinder
{
    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
    ...
    }
}

The Employee type affects bindingContext properties in BindModel(), like bindingContext.ModelMetadata and bindingContext.ModelType, that contains information about the model. Take a look at ModelMetaData: https://msdn.microsoft.com/pt-br/library/system.web.mvc.modelmetadata%28v=vs.108%29

like image 160
Renan Araújo Avatar answered Dec 16 '25 20:12

Renan Araújo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!