MVC 5 Model Binder Override

Viewed 4586

I wrote an override of the Model Binder.

public override object BindModel(Controller context, ModelBindingContext bindingContext)
{
    var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);

    object returnVal = null;

    if (value == null)
        returnVal = base.BindModel(controllerContext, bindingContext);
    else
    {
        /* custom logic here that never seems to get called.
            returnVal = something();
        */
    }

    return returnVal;
}

I also have a javascript service (in Angular) that makes an AJAX request to one of my controllers.

The AJAX request attempts to post a collection of ints. I tried stepping through the model binder, and it seems like value is always null. And by some magic, the base.BindModel() is still able to bind my collection to the correct C# object.

The problem with this is that I can't use my custom binder as the else block is never invoked. Is there another way I can get the value besides using the ValueProvider?

I also believe that before this custom binder was working correctly (from memory which could be wrong). I recently updated from 4.5 to 5.2.something. Is there anything that was updated that could've changed this behavior?

2 Answers
Related