irobinson/WebFormsMvp-DNN-Module-Template — Issue #9: Views shouldn't have logic in codebehind
Author: bdukes
Created: 2011-11-21 23:22:54+00:00
State: open

``

The view in MVP should be as simple as possible. The only thing that should be in the codebehind is event delegation (i.e. handle a click event and call the corresponding event on the view).

To that end, in the template, values should be filled via databinding instead of in code (e.g. in Settings, `DescriptionTextBox.Text = Model.Description` should be represented as ``).

To simplify code calling events, it's nice to set a default empty handler to remove the need to check for `null` (though not necessarily completely straightforward). e.g. `public event EventHandler SaveSetting = (_, __) => { };` (or `s` and `e` for argument names, if `_` and `__` are too opaque).

Ideally, the module action information would be coming from the presenter.

I'd propose that passing data to a presenter should happen through event args, rather than setting fields on the model (i.e. a custom view model has the fields that the view display, and a custom `EventArgs` has the info that the view collects). Certainly there is a grey area here, but I think it generally makes a nice separation.

In that scenario, `Page.IsValid` would be on the event args, so that can be moved to the presenter.

Skin.AddModuleMessage in the view should be replaced with `this.ShowMessage` in the presenter.
``