Skip to content

Instantly share code, notes, and snippets.

@Rookian
Last active May 12, 2016 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rookian/73926c1eecfc481568b53ef79522184d to your computer and use it in GitHub Desktop.
Save Rookian/73926c1eecfc481568b53ef79522184d to your computer and use it in GitHub Desktop.
BindToPropertyWith
public class BindToPropertyWith : CustomModelBinderAttribute
{
private readonly string _propertyName;
public BindToPropertyWith(string propertyName)
{
_propertyName = propertyName;
}
public override IModelBinder GetBinder()
{
return new DefaultPrefixModelBinder(_propertyName);
}
}
public class DefaultPrefixModelBinder : DefaultModelBinder
{
private readonly string _prefix;
public DefaultPrefixModelBinder(string prefix)
{
_prefix = prefix;
}
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
bindingContext.ModelName = _prefix;
return base.BindModel(controllerContext, bindingContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment