I've recently switch to MVP pattern with a Passive View approach. I feel it very comfortable to work with when the view interface exposes only basic clr types, such as string mapped to TextBoxes, IDictionary mapped to DropDownLists, IEnumerable mapped to some grids, repeaters.
我最近转向了MVP模式,采用了一种被动的视角。当视图界面只公开基本的clr类型时,我觉得使用起来很舒服,比如映射到文本框的字符串、映射到下拉列表的IDictionary、映射到某些网格的IEnumerable、中继器。
However, this last approach works only when from those grid I care only about one collumn. How can I map grid's multirow content inside IView ? For now, two solutions comes to my mind, both not brilliant:
然而,这种最后的方法只适用于我只关心一个集合的网格。如何在IView中映射grid的多行内容?现在,我想到了两种解决方案,都不是很高明:
- Create a DTO for the grid's content and expose the IEnumerable in IView, or
- 为网格的内容创建一个DTO,并在IView中公开IEnumerable,或者
- Expose the IEnumerable or just the "grid" as is in IView.
- 公开IEnumerable或者仅仅是IView中的“grid”。
First solution seems to break the Passive View rules while going closer to Supervising Controller pattern and second breaks the whole MVP pattern at all. How would do you handle this?
第一种解决方案似乎打破了被动视图规则,而更接近于监管控制器模式;第二种解决方案则彻底打破了整个MVP模式。你会怎么处理?
thanks, Łukasz
谢谢,Łukasz
1 个解决方案
#1
3
MVP makes webforms development much easier, except in cases like this. However, if you used TDD to verify that your IView really needs that grid of data, then I don't really see what the problem is.
MVP使得webforms的开发更加容易,除了这种情况。但是,如果您使用TDD验证您的IView确实需要数据网格,那么我就不知道问题出在哪里。
I assume you're trying to do something like this:
我猜你是想做这样的事情:
public interface IView
{
DataTable DataSource {get; set;}
}
public class View : IView {
private GridView _datasource;
public DataSource
{
get { return _datasource; }
set
{
_datasource = value;
_datasource.DataBind();
}
}
When used with the MVP pattern, I find this little pattern to be quite helpful.
当使用MVP模式时,我发现这个小模式非常有用。
#1
3
MVP makes webforms development much easier, except in cases like this. However, if you used TDD to verify that your IView really needs that grid of data, then I don't really see what the problem is.
MVP使得webforms的开发更加容易,除了这种情况。但是,如果您使用TDD验证您的IView确实需要数据网格,那么我就不知道问题出在哪里。
I assume you're trying to do something like this:
我猜你是想做这样的事情:
public interface IView
{
DataTable DataSource {get; set;}
}
public class View : IView {
private GridView _datasource;
public DataSource
{
get { return _datasource; }
set
{
_datasource = value;
_datasource.DataBind();
}
}
When used with the MVP pattern, I find this little pattern to be quite helpful.
当使用MVP模式时,我发现这个小模式非常有用。