2

入力モデルのプロパティに使用するモデル バインダーを指定したいと考えています。

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; }
}

ただし、ModelBinderAttribute をプロパティに適用することはできません。メソッドパラメーターに適用できるので、これはばかげているようです。この制限を回避するにはどうすればよいですか?

4

2 に答える 2

1

あなたはおそらくここのようにあなた自身を実装しなければなりませんPropertyBinderMVCプロパティバインダー

于 2012-10-22T18:15:31.583 に答える
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.

于 2010-01-03T23:33:03.243 に答える