模型视图控制器
有人可以帮助我理解要在 WebForms 上实现的模型-视图-控制器方法吗?我对以下几件事感到困惑:
如果我们有 ABC.ASPX 和 ABC.CS 文件,那么视图是什么?它只是 ABC.ASPX 文件吗?或者.ASPX + .CS 文件的组合?
我们是否将 ABC.CS 文件视为控制器?如果不是,它会是控制器的一个单独的类吗?
数据库连接和数据检索是否进入模型或由模型调用的单独类?
有人可以举一个在网络表单中实现模型-视图-控制器的简单例子吗?
更新
大家好,我的问题是如何使用 WebForms 实现模型-视图-控制器方法,而不是关于 ASP.NET MVC2.0。对于造成的混乱,我深表歉意。
干杯
Can someone help me understanding Model-View-Controller method to be implemented on WebForms? I am confused on couple of things:
If we have ABC.ASPX and ABC.CS files, what is view? is it only ABC.ASPX file? or combination of .ASPX + .CS file?
do we consider ABC.CS file as controller? If no, will it be a seperate class for controller?
Does database connection and data retreival go into Model or a seperate class which will be called by Model?
Can someone give a simple example for implementing Model-View-Controller in webforms?
Update
Hi guys, my question is how to implement Model-View-Controller methodology using WebForms not about ASP.NET MVC2.0. I apologise for the confusion.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我明白您想要做什么:您想要在 ASP.NET WebForms 应用程序之上实现 MVC 架构。很公平。
我只能说祝你好运!我在那里&做到了。我多么后悔这样做...:P
请记住:ASP.NET WebForms 是一个巨大的抽象,它试图将 Web 变成一个有状态的、基于事件的、类似 Windows 的环境,而无需任何操作。任何脱钩的担忧。因此,尝试在上面创建一个无状态、高度解耦且非基于事件的架构,遗憾的是,近乎疯狂。
请启发自己,进入真正的 ASP.NET MVC 世界...:-)
PS: 有些人声称成功实现了 MVP (Model-View- Presenter)架构高于 ASP.NET WebForms。为他们感到羞耻(但如果你真的想的话,你可以尝试)!
I guess I understood what you want to do: you want to implement a MVC architecture above an ASP.NET WebForms application. Fair enough.
All I can say is good luck! Me being there & done that. And how I regretted doing so... :P
Remember: ASP.NET WebForms is a huge abstraction, that tries to make the web into a statefull, event-based, windows-like environment, without any concern of decoupling whatsoever. So, trying to create an stateless, highly-decoupled and non-event-based architecture above that is, sorry to say, near insane.
Please, enlighten yourself and come to the real ASP.NET MVC world... :-)
PS: some people claim of having success implementing a MVP (Model-View-Presenter) architecture above ASP.NET WebForms. Shame on them (but you can try if you really want to)!
正如其他人发布的那样,有很多关于 MVC 的信息,所以我会回答你的问题......
两者都是...但是 .cs 文件被引用为代码隐藏,但两者都构成了视图。
不,控制器将是一个单独的类。
你可以选择任何一种方式。您可以将此逻辑放入模型中,但是您也可以将其功能化为服务,然后模型可以根据需要调用这些服务。恕我直言,第二条路线是要走的路,因为我不想让我的模型依赖于外部实体,而且它也使测试模型变得更容易,因为您可以将服务测试与模型测试分开。
可以在此处看到图表,其中有一些很棒的图像作为参考点。
As others have posted there is a lot of information out there on MVC, so I'll answer your question...
It is both...however the .cs file is referenced as code behind but both make up the view.
No, a separate class would be the controller.
You could go either way. you could place this logic in the model, however you could also functionalize it out into services, which can then be called as needed by the model. IMHO the second route is the way to go, as I don't want to make my model dependent on external entities and it also makes testing the model easier, as you can separate out the services testing from the model testing.
Diagram can be seen here, which has some great imagery as reference points.