Custom model binder for a property

前端 未结 4 1247
遇见更好的自我
遇见更好的自我 2020-11-30 04:08

I have the following controller action:

[HttpPost]
public ViewResult DoSomething(MyModel model)
{
    // do something
    return View();
}

4条回答
  •  独厮守ぢ
    2020-11-30 04:12

    override BindProperty and if the property is "PropertyB" bind the property with my custom binder

    That's a good solution, though instead of checking "is PropertyB" you better check for your own custom attributes that define property-level binders, like

    [PropertyBinder(typeof(PropertyBBinder))]
    public IList PropertyB {get; set;}
    

    You can see an example of BindProperty override here.

提交回复
热议问题