如何在 WebFormsMvp 中从 View 到 Presenter 获取多个属性值?
在 WebFormsMvp 页面中从视图到演示器获取业务对象的多个属性值的最佳方法是什么?
请记住这个问题数据源。
这是我的建议:
场景是,我有一个名为 Quote 的业务对象,我想从数据库加载它,编辑然后保存。 Quote 类有很多属性。该表格涉及其中大约 20 个属性。我有现有的方法可以将 Quote 对象加载到数据库或从数据库保存。我现在需要将这一切连接在一起。
因此,在演示者的 View_Load 处理程序中,我打算执行以下操作:
public void View_Load(object sender, EventArgs e)
{
View.Model.Quote = quoteService.Read(quoteId);
}
然后按如下方式绑定所有控件:
<asp:TextBox ID="TotalPriceTextBox" runat="server"
Text="<%# Model.Quote.TotalPrice %>" />
一切都好,数据在屏幕上。
然后,用户进行一系列更改并点击“提交”按钮。这是我不确定的地方。
我创建了一个名为 QuoteEventArgs 的类,公开了表单可以编辑的 20 个属性。当视图引发“提交”按钮的事件时,我将这些属性设置为后面代码中控件的值。然后提出事件供演示者响应。演示者从数据库重新加载 Quote 对象,设置所有属性并将其保存到数据库。
这是正确的方法吗?如果不是,那是什么?
What is the best way to get a number of property values of a business object from the View to the Presenter in a WebFormsMvp page?
Bearing in mind this issue with DataSources.
Here is what i propose:
The scenario is, I have a business object called Quote which i would like to load form the database, edit and then save. The Quote class has heaps of properties on it. The form is concerned with about 20 of these properties. I have existing methods to load/save a Quote object to/from the database. I now need to wire this all together.
So, in the View_Load handler on my presenter i intend to do something like this:
public void View_Load(object sender, EventArgs e)
{
View.Model.Quote = quoteService.Read(quoteId);
}
And then bind all my controls as follows:
<asp:TextBox ID="TotalPriceTextBox" runat="server"
Text="<%# Model.Quote.TotalPrice %>" />
All good, the data is on the screen.
The user then makes a bunch of changes and hits a "Submit" button. Here is where I'm unsure.
I create a class called QuoteEventArgs exposing the 20 properties the form is able to edit. When the View raises the Submit button's event, I set these properties to the values of the controls in the code behind. Then raise the event for the presenter to respond to. The presenter re-loads the Quote object from the database, sets all the properties and saves it to the database.
Is this the right way to do this? If not, what is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“更好的方法”(/替代)是使用双向绑定,因此将传回 Presenter 进行处理的将是您的 Quote 对象。
这可以通过将 asp:FormView 与指定 UpdateMethod 和 Bind 的 mvp:PageDataSource 结合使用来实现() 方法。
WebFormsMVP 示例项目通过“EditWidgetControl”演示了这一点,包括视图代码隐藏文件所需的方法。
作为一个选项,您的视图可以简单地仅实现 asp:FormView 的 EditItemTemplate,利用 FormView 上的 DefaultMode="Edit" 。
示例结构:
代码隐藏:
"A nicer way" (/alternative) is to make use of the 2-way binding, therefore what will be passed back to the Presenter for processing will be your Quote object.
This can be achieved through the use of an asp:FormView in conjunction with the mvp:PageDataSource that specifies an UpdateMethod and the Bind() method.
The WebFormsMVP sample project demonstrates this via the 'EditWidgetControl', including the methods required on the View code-behind file.
As an option your view can simply implement only the EditItemTemplate for asp:FormView making use of DefaultMode="Edit" on the FormView.
Sample Structure:
Code-behind:
如何在 FormView 中使用 GridView。
因为我有列表来填充实体中的网格。
How to use the GridView inside a FormView.
Because I have list to populate the grid in a entity.