できるはずだと思います。これを試して:
public class FooModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
FooModel fooModel = bindingContext.Model as fooModel;
if (fooModel != null)
{
// Do your verification stuff in here
// Updating any properties of your Model.
// Or you could retrieve something else entirely and return it if you like
// Let's pretend we just want to verify the model and set some property or other.
fooModel.NonceOkay = DoVerification(fooModel);
fooModel.NextAction = WorkOutWhereToGoNext(fooModel);
// or whatever
}
return fooModel;
}
}
DoVerification
ModelBinder に存在することもできますが、別の場所に存在する方がよい場合があります。
次に、これを Global.asax の Application_Start に貼り付けます。
ModelBinders.Binders.Add(typeof(Foo), new FooModelBinder());