本文介绍了在presentation层控制修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的GridView和结合发生在presenter层数据,但例如小区1已被修改并转换为超链接控制,然后我打电话给在presenter层的RowDataBound事件,做这里面修改event.Is这是一个好有MVP?

I am using GridView and the data binding occurs in Presenter layer but the cell 1 for example has to be modified and converted to a HyperLink control then I have to call the RowDataBound event in Presenter layer and do the modification inside that event.Is this a OK with MVP?

推荐答案

我一般都在数据绑定,并在视图级别事件处理。通过在presenter这样做,你所创建的presenter,并要避免视图之间的相关性。我不知道你将如何单元测试presenter方法​​的呼唤 .DataBind()上一个GridView。

I would typically do the data binding and event handling at the View level. By doing it in the Presenter, you are creating a dependency between the Presenter and the View that you want to avoid. I'm not sure how you would unit test a Presenter method that's calling .DataBind() on a GridView.

我会做什么(什么,我认为这是标准)是一种属性添加到$ C $您的视图类的那些重新presents为GridView数据c-后面。所以说,你的GridView显示的员工,物业可能是这样

What I would do (and what I believe is standard) is add a property to the code-behind of your view class that represents the data for the GridView. So say your GridView shows employees, the property might be something like

public List<Employee> Employees 
{ 
    get { return (List<Employee>)GridView1.DataSource; }
    set // The Presenter calls this
    {
        GridView1.DataSource = value;
        GridView1.DataBind();
    }
}

在presenter将简单地设置该属性,然后你会做数据绑定和事件处理按照通常的做法与web表单。

The presenter would simply set this property and then you would do the data binding and event handling as you typically would with webforms.

这也将让您进行单元测试presenter如果你想。假设您的视图实现一个接口,可以使用不同的执行单元测试,即制定者不会把 .DataBind(),它可能仅仅是一个自动属性。你可以创建一个模拟来看,它传递给presenter,然后测试你的属性不为null,或沿着这些线路的东西。

This will also allow you to unit test your Presenter if you wish to. Assuming that your view implements an interface, you can use a different implementation for your unit test, i.e. the setter wouldn't call .DataBind(), it might simply be an automatic property. You could create a mock view, pass it to the Presenter, and then test that your property is not null, or something along those lines.

这篇关于在presentation层控制修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 08:04