Last active
May 12, 2016 14:27
-
-
Save Rookian/73926c1eecfc481568b53ef79522184d to your computer and use it in GitHub Desktop.
BindToPropertyWith
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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