Change model values before process through actions

137 views Asked by At

How can I change sent data to controllers some where like OnActionExcuting?

Imagine I want develop a middle ware (something like asp.net attributes) replace all "a" to "A" and then bind values to model(in all action just can see "A"!)

1

There are 1 answers

0
janhartmann On

You can create a custom ModelBinder and use it on specific actions:

[HttpPost]
public ActionResult CreateSomething([ModelBinder(typeof(MyCustomModelBinder))] Something something) 
{

}

public class MyCustomModelBinder : DefaultModelBinder
{
    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        // Do something
        return base.BindModel(controllerContext, bindingContext);
    }
}