Using a custom mediation for a controller action argument

I have a controller action that looks like this:

public ActionResult DoSomethingCool(int[] someIdNumbers)
{
    ...
}

I would like to be able to use a custom mediator to create this array of identifiers from a list of checkboxes on the client. Is there any way to link this argument only? Also, is there a way for the model binder to detect the name of the argument used? For example, in my modular binder, I would like to know that the argument name was "someIdNumbers".

+5
source share
2 answers

The attribute ModelBindercan be applied to individual parameters of the action method:

public ActionResult Contact([ModelBinder(typeof(ContactBinder))]Contact contact)

Here the parameter contactis linked with ContactBinder.

+11

, ModelBindingContext.ModelName

public class MyModelBinder : IModelBinder
{
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var thisIsTheArgumentName = bindingContext.ModelName;
    }
}
+6

All Articles