ASP.NET Web窗体 - 模型 - 视图 - presenter和用户控件 [英] ASP.NET Web Forms - Model View Presenter and user controls

查看:107
本文介绍了ASP.NET Web窗体 - 模型 - 视图 - presenter和用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来使用MVP模式,我只是想确保对从用户控件中调用presenter的最佳方式。

I'm new to using the MVP pattern and I just want to make sure on the best way to call a presenter from within a user control.

MyPage.aspx 的有presenter的我的presenter

MyPage.aspx has a presenter MyPresenter

该网页包含通过属性接受我的页面的presenter用户控件从我的页面我建立

The page contains a user control which accepts MyPage's Presenter via a property which I setup from MyPage

MyUserControl.Presenter = this.Presenter

现在我试图调用的方法1 的的presenter它检索一些配置,并将其从用户控制的观点。在

I'm now trying to call Method1 within the presenter which retrieves some config and sets it on the view from the user control.

Presenter.Method1(); // calls method and sets config to the view

我的问题是首先


  1. 我应该使用presenter以这种方式在用户控件?

  2. 如果是这样,它是有效的可以通过用户控件访问视图值,如下所示。

  1. should I be using the presenter in the user control in this way?
  2. If so, is it valid to be accessing the view value via the user control as shown below.

presenter.View.MyData

Presenter.View.MyData

我只是想确保我不会走下这个!

I just want to make sure I'm not going off down the completely wrong path with this!

推荐答案

我用做的是有它只是为用户控件presentation和一个$ P负责每个用户控件的一个presenter $ psenter的每一页(的.aspx)。
我觉得让事情分开也有助于保持你将有骨感presenter这是只负责的UI的一小部分。
用户控件也将是自成一体的方式,你可以重新使用它们为presentation逻辑从页面presentation逻辑是处于分离状态。

What I use to do is to have one presenter for each user control which is responsible only for the user control presentation and one presenter for each page (.aspx). I think keeping things separated helps also for maintaining as you will have "skinny" presenter which are responsible only of a small section of the UI. The user control will be also "self-contained" in the way that you can reuse them as the presentation logic is kept separated from the page presentation logic.

看看以下职位:

MVP和用户控件和调用

这篇关于ASP.NET Web窗体 - 模型 - 视图 - presenter和用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆