MVP icon indicating copy to clipboard operation
MVP copied to clipboard

Interaction between view and model

Open Leodez opened this issue 11 months ago • 1 comments

Hi, I saw the following in your view code:

var model = (Model)row.DataBoundItem;
IncreaseAClick(model);

I'm new to MVP and your repository has helped me a lot.

My question is: Isn't the view supposed to not know about the model or at least not interact directly with it?

Sorry if this is not the right place to ask a question, if I should ask in another way I'd appreciate the indication.

Leodez avatar Jan 19 '25 23:01 Leodez

Hello @Leodez, great question!

There are 2 types of the pattern: passive view and supervising controller (You can find more information in google).

Supervising controller uses databinding for communicating with the view. Databinding is extremely convenient especially in .NET because it allows simplifying the interaction and can do all the job without a single line of code.

In my example, I use both approaches. In places where databinding is not convenient, I use direct presenter communication with a view.

Regarding your question, View communicates with Model thought databinding, in this particular case we can pass a row identity to the event. In the example, I use Model for simplicity but I don't see any issues with using Models in such a way.

agre1981 avatar Jan 22 '25 09:01 agre1981