このように、ある種のマルチバインダーを使用することは可能ですか?
[Authorize]
[AcceptVerbs("POST")]
public ActionResult Edit([CustomBinder]MyObject obj)
{
///Do sth.
}
私もこのようにデフォルトのバインダーを設定した場合:
protected void Application_Start()
{
log4net.Config.XmlConfigurator.Configure();
RegisterRoutes(RouteTable.Routes);
ModelBinders.Binders.DefaultBinder = new Microsoft.Web.Mvc.DataAnnotations.DataAnnotationsModelBinder();
}
私が望むのは、DataAnnotationsBinder (stringlength、regexps などのデータを検証する) と、さらにフィールド値を設定するカスタム バインダーの利点を得ることです。
EntitiyFramework を使用し、DataAnnotations と組み合わせて、次のようなコンストラクトになるため、このためにバインダーを 1 つだけ作成することはできません。
[MetadataType(typeof(MyObjectMetaData))]
public partial class MyObject
{
}
public class MyObjectMetaData
{
[Required]
[StringLength(5)]
public object Storename { get; set; }
}