This project is read-only.

'Codeless' WebForms version?

Jan 25, 2010 at 12:07 PM

Hi Craig, thanks for the great reference apps, it's really helped me to grok MVVM.

It struck me that you didn't yet have a version of a WebForms MVVM implementation using ObjectDataSource and templated data bound controls.

While I'm not keen on this 'codeless' approach for anything but the simplest application, it may still be worth addding an implementation for the sake of completeness?

I started playing around with an implementation but I started to have doubts about whether this was worth the effort to continue and whether it would confuse the issue and deviate too far from the spirit of the MVVM pattern. I hope others may have some thoughts to share here?

Imagine how this could work:

I added a new class in the Model folder(maybe not the right place) which I called WebFormsViewModelDataSource (maybe not the best name). Methods in this class were very similar to WebFormsViewModel except that the methods needed to be static (so no instance fields this time), and I attributed them with System.ComponentModel.DataObjectMethodAttribute (to make the DataSource controls happy).

I started binding a ListView where the ItemTemplate displayed only 3 of the properties of the ProductListView, but then when I started to build an EditItemTemplate when I obviously realised (d'oh) that the ProductListView object doesn't contain all of the properties that I'd want to 2-way bind to controls within this EditItemTemplate (i.e. no Price or ReleaseDate).

My next step could be to change ProductListView class or create something like a ProductListAndEditView which is able to support the properties required for both viewing in a list and for editing.

Naturally I felt that this was starting to deviate from the spirit of having view classes responsible for only one thing at a time (i.e. only viewing or only editing not both).

What does everyone else feel about this?