We have a hierarchical model of the shape (yuml-ized):
![[Order] 1 Parent - Items 0..* [LineItem]](https://i.stack.imgur.com/R6CHW.png)
And a controller action that takes an Order-typed parameter:
public ActionResult UpdateOrder(Order order)
{
...
}
With the posted form having fields for the line items, too, we get a tree of objects from the MVC's model binding where as the binders create a new order object for each order to be bound.
The question: Is it possible to have the binding mechanism set the Parent property of each LineItem to the Order object they are being added too?
I take it that the binder that binds the Order object is responsible for executing a binder for each child object, too, by calling BindModel on the child object binders. We already have custom implementations (inheriting from DefaultModelBinder) in place: A OrderBinder as well as a LineItem binder.
How can our LineItem.BindModel method find out whether the LineItem being bound is "stand-alone" or about to be added to an Order whose binding is in progress, and if the latter is the case, how do we get the reference to that Order?