模型视图控制器

发布于 2024-09-28 19:48:02 字数 424 浏览 6 评论 0原文

有人可以帮助我理解要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野稚 2024-10-05 19:48:03

我想我明白您想要做什么:您想要在 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)!

南城旧梦 2024-10-05 19:48:03

正如其他人发布的那样,有很多关于 MVC 的信息,所以我会回答你的问题......

如果我们有 ABC.ASPX 和 ABC.CS 文件,
什么是视图?是不是只有ABC.ASPX
文件?或 .ASPX + .CS 的组合
文件?

两者都是...但是 .cs 文件被引用为代码隐藏,但两者都构成了视图。

我们是否将 ABC.CS 文件视为
控制器?如果不是,这将是一个
控制器的单独类?

不,控制器将是一个单独的类。

是否有数据库连接和数据
检索进入模型或单独的
模型将调用哪个类?

你可以选择任何一种方式。您可以将此逻辑放入模型中,但是您也可以将其功能化为服务,然后模型可以根据需要调用这些服务。恕我直言,第二条路线是要走的路,因为我不想让我的模型依赖于外部实体,而且它也使测试模型变得更容易,因为您可以将服务测试与模型测试分开。

可以在此处看到图表,其中有一些很棒的图像作为参考点。

As others have posted there is a lot of information out there on MVC, so I'll answer your question...

If we have ABC.ASPX and ABC.CS files,
what is view? is it only ABC.ASPX
file? or combination of .ASPX + .CS
file?

It is both...however the .cs file is referenced as code behind but both make up the view.

do we consider ABC.CS file as
controller? If no, will it be a
seperate class for controller?

No, a separate class would be the controller.

Does database connection and data
retreival go into Model or a seperate
class which will be called by Model?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文