ASP.NET Web 窗体 - 模型视图演示器和用户控件

发布于 2024-10-30 04:45:29 字数 542 浏览 0 评论 0原文

我是使用 MVP 模式的新手,我只是想确保从用户控件中调用演示者的最佳方式。

MyPage.aspx 有一个演示者 MyPresenter

该页面包含一个用户控件,该控件通过我从 MyPage 设置的属性接受 MyPage 的演示者,

MyUserControl.Presenter = this.Presenter

我现在尝试调用 Method1 在演示者中,它检索一些配置并将其设置在用户控件的视图上。

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

我的问题首先是

  1. 我应该以这种方式在用户控件中使用演示者吗?
  2. 如果是这样,通过用户控件访问视图值是否有效,如下所示。

    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

  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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩起发的微风 2024-11-06 04:45:29

我用来做的是为每个用户控件配备一个演示者,该演示者仅负责用户控件的演示,并为每个页面(.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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文