This project is read-only.

There should be other possibilities than TryUpdateModel available from drivers


Model binding is great and covers most situations, but in those rare occurrences where it's not enough, the only solution is to implement your own model binder, which is something of a dark art.
Instead, drivers should have access to lower-level APIs that give direct access to context information that regular controllers have, such as the form, querystring, cookies, etc. Bonus points for still providing prefix filtering.


pszmyd wrote Oct 25, 2012 at 5:13 AM

You can access current HttpContext from everywhere.
Inject IWorkContextAccessor in ctor and use _workContextAccessor.Current().HttpContext.

pszmyd wrote Oct 25, 2012 at 5:17 AM

Bertrand, I can't believe you actually reported this;)

BertrandLeRoy wrote Oct 25, 2012 at 6:53 AM

Tss tss tss. Of course you can. Now try to guess why controllers expose a controller context rather than letting people go through an untestable singleton...

pszmyd wrote Oct 25, 2012 at 3:24 PM

Agreed, but you wrote "access" and it's still perfectly possible. Testability is a different thing, I guess?

On the other hand - the update Editor method already gets a reference to the actual controller (through updater), so it's also possible to retrieve the underlying ControllerContext.

BertrandLeRoy wrote Oct 26, 2012 at 2:04 AM

You're splitting hair. I had talked to Sébastien before filing this. It's true that you can go through updater but if I'm not mistaken you would have to cast to controller first. It's a bit of a mess, and not very discoverable don't you think?

pszmyd wrote Oct 26, 2012 at 4:15 AM

Yeah, casting is necessary. It's not the cleanest approach, right, and it's also not available in Display method... Extending IUpdateModel with Context property is ok, but adding Context property to ContentPartDriver<T> looks equally good.

BertrandLeRoy wrote Oct 26, 2012 at 4:46 AM

Adding it as a property of the driver would make it consistent with controllers. As drivers are supposed to be analogous to controllers...