So, I’m attempting to rewrite an old asp.net app and thought I’d do it in in MVP this time.
The app displays a dynamically generated form by placing labels and input fields in a table.
What I get from my Model is a list of entities that describe what control’s should be rendered.
Now this list needs to be converted into a table with a lable and control on each row, but I can’t decide where and how to do this.
These are the scenario’s I could think of, but I have no idea which one is right according to MVP:
- For each item create a table row in the presenter and call
View.AddRow(row) - Create a list of table rows in the presenter and call
View.AddRows(list) - For each item call
View.CreateRow(info)
Any ideas?
Thanks!
The key of the MVP pattern is to separate the concerns between the view and the presenter. The presenter only has to set the list of entities and whether the data is presented as a table using a GridView, Repeater etc is the concern of the view.
If I were doing what you would describe I would use a ‘view model’ class to act as a wrapper for creating the controls:
My View would look as follows:
And the presenter:
The property setter on the view implementation (the .ASPX code behind) would look as:
Using the view model would make unit testing easier and keep a cleaner separation of concerns.