MVC架构中的数据转换
我在项目中使用 ZedGraph 进行图表绘制,并且使用 MVC 架构。我的控制器将从模型中获取需要绘制的数据,并将其发送到视图进行绘制。我的疑问是,将这些数据从控制器发送到“C# 自然类型”中的视图(作为数据表或数组列表)是否正确,并将其在视图内转换为 PointPairList (zedgraph 的类型),或者视图不得包含此类里面的代码和控制器必须发送已经转换为绘图类型的数据?
谢谢。
I am using ZedGraph for charting in my project, and I am using MVC architecture. My controller will get the data I need to plot from the model and will send it to the view to plot. My doubt is, is it correct to send this data from controller to view in a "C# natural type", as data table or array list, and convert it inside the view to PointPairList (zedgraph's type) or the view must not contain this kind of codes inside and the controller must send the data already converted to the plotting type?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种情况是选择 MVVM 架构的重要原因之一(假设您有这种奢侈)。在 MVVM 中,此类代码将由视图模型负责,因此视图可以仅限于 GUI 代码,而模型仅维护数据表示。
您能否详细说明一下控制器如何向视图发送数据,因为在 MVC 模式中,视图通常会查询模型来获取数据。
因此,使用 MVC,您可以将转换代码放置在视图中,而不需要控制器将数据推送到视图。
This situation is one of the big reasons for choosing an MVVM architecture (assuming you have that luxury). In MVVM, this kind of code would be the responsibility of the View-Model, so the View can be restricted to GUI-only code, while the Model maintains solely data representation.
Could you perhaps elaborate more on how the controller is sending the View the data, because in the MVC pattern, the View generally queries the Model to obtain data.
So using MVC you can place the conversion code in the View without the need for the Controller to be pushing data to the View.