模型视图展示器和用户控件

模型视图展示器和用户控件

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

问题描述

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

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 有一个演示者 MyPresenter

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

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

MyUserControl.Presenter = this.Presenter

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

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. 我应该以这种方式在用户控件中使用演示者吗?
  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!

推荐答案

我的做法是为每个用户控件设置一个presenter,只负责用户控件的呈现,每页一个presenter (.aspx).我认为将事物分开也有助于维护,因为您将拥有瘦"的演示者,它只负责 UI 的一小部分.用户控件也将是自包含"的,您可以重用它们,因为呈现逻辑与页面呈现逻辑保持分离.

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 和 UserControls 和调用

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

08-30 07:28