ASP.Net MVC model binding child list property

89 Views Asked by At

I have a controller action method

[HttpPost]
public ActionResult Create(MyItem item){
    ...
}

My type definitions look like this

public class MyItem{
    ...
    public List<MySubItem> MySubItems{ get; set; }
}

public class MySubItem{
    ...
}

I have created a custom model binder for List<MySubItem> and registered it

ModelBinders.Binders.Add(typeof(List<MySubItem>), new MySubItemsModelBinder());

I was expecting that when the automatic model binder was binding MyItem it would use MySubItemsModelBinder when it was binding the List<MySubItem> MySubItems property of MyItem but it does not.

What Im wondering is if my expectation is incorrect or if I have misconfigured somewhere?

0

There are 0 best solutions below