3

I want to specify the model binder to use for a property of my input model.

public class SendEmailInput
{
    [Required, EmailAddress]
    public string From { get; set; }
    [Required]
    public string To { get; set; }
    [Required]
    public string Subject { get; set; }
    [Required, ModelBinder(typeof(RadEditorModelBinder))]
    public string Body { get; set; }
}

However the ModelBinderAttribute cannot be applied to properties. This seems stupid since I can apply it to method parameters. What should I do to work around this limitation?

1
  • damn it! I went and reorganized things expecting to be able to do this (I have a model that is sometimes bound with a complex modelbinder and sometimes with JSON) Commented Jan 12, 2013 at 23:51

2 Answers 2

1

You probably have to implement your own PropertyBinder like here: MVC Property Binder

Sign up to request clarification or add additional context in comments.

Comments

0

In wanting to specify which model binder to use, is your intention to be able to mix and re-use exising logic of the model binders? If so, you can probably combine your logic in the custom binder itself (i'm guessing your "RadEditorModelBinder"). This way, you use 1 model binder, but the model binder itself uses different techniques based on the incoming properties.

What do you think, would that be a good alternative for you? If so, see this post for further discussion.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.