ASP.NET Web 窗体 - 模型视图演示器和用户控件
我是使用 MVP 模式的新手,我只是想确保从用户控件中调用演示者的最佳方式。
MyPage.aspx 有一个演示者 MyPresenter
该页面包含一个用户控件,该控件通过我从 MyPage 设置的属性接受 MyPage 的演示者,
MyUserControl.Presenter = this.Presenter
我现在尝试调用 Method1 在演示者中,它检索一些配置并将其设置在用户控件的视图上。
Presenter.Method1(); // calls method and sets config to the view
我的问题首先是
- 我应该以这种方式在用户控件中使用演示者吗?
如果是这样,通过用户控件访问视图值是否有效,如下所示。
Presenter.View.MyData
我只是想确保我不会走上完全错误的道路!
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 has a presenter MyPresenter
The page contains a user control which accepts MyPage's Presenter via a property which I setup from MyPage
MyUserControl.Presenter = this.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
My question is firstly
- 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
I just want to make sure I'm not going off down the completely wrong path with this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用来做的是为每个用户控件配备一个演示者,该演示者仅负责用户控件的演示,并为每个页面(.aspx)配备一个演示者。
我认为将事物分开也有助于维护,因为您将拥有“瘦”演示者,它们只负责 UI 的一小部分。
用户控件也将是“独立的”,您可以重用它们,因为表示逻辑与页面表示逻辑保持分离。
看看下面的帖子:
MVP 和 UserControls 以及调用
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.
have a look at the following post:
MVP and UserControls and invocation