Custom Model binder not firing
Posted
by mare
on Stack Overflow
See other posts from Stack Overflow
or by mare
Published on 2010-04-06T11:01:51Z
Indexed on
2010/04/06
11:03 UTC
Read the original article
Hit count: 770
This is my custom model binder. I have my breakpoint set at BindModel but does not get fired with this controller action:
public ActionResult Create(TabGroup tabGroup)
...
public class BaseContentObjectCommonPropertiesBinder : DefaultModelBinder
{
public new object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
if (controllerContext == null)
{
throw new ArgumentNullException("controllerContext");
}
if (bindingContext == null)
{
throw new ArgumentNullException("bindingContext");
}
BaseContentObject obj = (BaseContentObject)base.BindModel(controllerContext, bindingContext);
obj.Modified = DateTime.Now;
obj.Created = DateTime.Now;
obj.ModifiedBy = obj.CreatedBy = controllerContext.HttpContext.User.Identity.Name;
return obj;
}
My registration:
// tried both of these two lines
ModelBinders.Binders[typeof(TabGroup)] = new BaseContentObjectCommonPropertiesBinder();
ModelBinders.Binders.Add(typeof(TabGroup), new BaseContentObjectCommonPropertiesBinder());
© Stack Overflow or respective owner