ASP.NET Web窗体 - 模型 - 视图 - presenter和用户控件 [英] ASP.NET Web Forms - Model View Presenter and user controls
问题描述
我是新来使用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
我的问题是首先
- 我应该使用presenter以这种方式在用户控件?
-
如果是这样,它是有效的可以通过用户控件访问视图值,如下所示。
- should I be using the presenter in the user control in this way?
If so, is it valid to be accessing the view value via the user control as shown below.
presenter.View.MyData p>
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.
看看以下职位:
这篇关于ASP.NET Web窗体 - 模型 - 视图 - presenter和用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!