Asp.Net WebForms上的MVP [英] MVP on Asp.Net WebForms

查看:165
本文介绍了Asp.Net WebForms上的MVP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不清楚这一点....



当在视图中有一个gridview时,控制器必须设置数据源,列等等?或者我只需要暴露DataBinding的东西,从控制器触发它,让视图上的html / codebehind处理所有的渲染和接线?



要更多精确:在视图中我应该有

  private GridView _gv 
public _IList< Poco>来源{
get {_gv.DataSource;}
set {_gv.DataSource = value;
_gv.DataBind();}
}

或者应该来自 MVP模式 - 被动视图并通过IView(Asp.Net,Web窗体)暴露复杂类型

  private GridView _datasource; 
public DataSource
{
get {return _datasource; }
set
{
_datasource = value;
_datasource.DataBind();
}
}

也许我错了...



在哪里可以找到一个不是ASP.Net的MVP中的Hello world示例的示例。

解决方案

您的控制器应负责设置数据绑定的结果。所以例如,您的webform / usercontrol(View)可能会将数据源作为对象属性公开,您的View应该是知道如何处理收到它时:

  public MyObject DataSource 
{
set
{
_datasource = value;
_datasource.DataBind();
}
}

所以如果你需要一个ItemDataBound事件,在视图中仍然会处理它。即使事件中可能存在业务逻辑。如果您需要在事件中有业务逻辑,那么在将它传递给视图之前,我将其放在MyObject结果中。



所以一个例子是MyObject的属性为AllowDelete,在ItemDataBound中,此属性的值确定GridView中的列是否已启用。


I'm not clear about this....

When having a gridview on the View, is the controller who has to set up the Data source, columns, etc? or I just have to expose the DataBinding stuff, fire it from the controller and let the html/codebehind on the view handle all the rendering and wiring up?

To be more precise: on the view should I have

private GridView _gv
public _IList<Poco> Source { 
    get {_gv.DataSource;}
    set {_gv.DataSource = value;
         _gv.DataBind();}
}

Or should it be (from MVP pattern - Passive View and exposing complex types through IView (Asp.Net, Web Forms))

private GridView _datasource;
public DataSource 
{
  get { return _datasource; }
  set 
  { 
    _datasource = value; 
    _datasource.DataBind(); 
  }
}

Maybe I'm having it all wrong ....

Where can I find an example that is not a "Hello world" example on MVP for ASP.Net???

解决方案

Your controller should be in charge of setting the "result" of the databinding. The view is in charge of displaying it propertly.

So for example, your webform/usercontrol (View) could have the data source exposed as an object property that your View should know how to handle when it receives it:

public MyObject DataSource 
{
  set 
  { 
    _datasource = value; 
    _datasource.DataBind(); 
  } 
}

So if you need to have an ItemDataBound event, I would still handle it in the view. Even though there could be business logic in the event. If you need to have business logic in the event, I would put it in the MyObject result before it is passed to the view.

So an example would be to have a property of "MyObject" be "AllowDelete" and in your ItemDataBound, the value of this property determines if a column in the GridView is enabled or not.

这篇关于Asp.Net WebForms上的MVP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆