类似 ASP.NET winforms 的理念和页面生命周期经常妨碍我
在同一个网站中使用 MVC + 经典 Web 表单
现在 我想知道是否可以混合使用 MVC 和经典 Web 表单(我不想重新实现我已经做过的事情,即使这会使代码变得非-同质...)
原始问题
我对 ASP.NET(以及一般的 Web 编程)的理解越深入,我就越不喜欢 ASP.NET 页面生命周期及其类似 winforms 的范例。 我越来越相信,通过自己的处理程序编写,或者最多使用没有任何数据绑定控制的纯 .aspx 模板,我可以在更短的时间内获得更好的结果。
每次我学习 ASP.NET 的做事方式时,我都会感觉自己浪费了时间,最终又重新发明了轮子。
您是否熟练使用 System.Web.UI.* 控件?
您不会对页面生命周期感到困惑吗?
您不觉得在每个页面上放置一个 SQLDataSource 会产生难以维护的代码吗?
更新
我简直不敢相信我是唯一一个有这种感觉的人,现在我知道我是对的。 我正在观看一些有关 MVC 的视频,它看起来与我正在寻找的内容完全一样。 明天我将安装并尝试一下。
MVC + classic webforms in the same website
Now I am wondering if it was possible to mix MVC and classic webforms (I don't want to reimplement what I've already done even if this makes the code non-homogeneous...)
Original question
The more I improve my understanding of ASP.NET (and web programming in general) the more I dislike ASP.NET page-lifecycle and its winforms-like paradigm. I'm more and more convinced that I'd get better results in less time by writing by own handlers or, at most, using plain .aspx templating without any databound control.
Every time I learn the ASP.NET-way of doing something I'm left with the feeling that I have wasted my time and I end up re-inventing the wheel.
Do you proficently use System.Web.UI.* controls?
Don't you get confused by the page lifecycle?
Don't you feel like that putting a SQLDataSource on each page produces unmaintainable code?
Update
I couldn't belive I was the only one who felt like that and now I know I was right. I'm watching some videos about MVC and it looks exactly like what I was looking for. Tomorrow I will install and try it out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
什么? 为什么不使用
SqlConnection
?What? Why aren't you using
SqlConnection
?ASP.NET MVC 正是为那些与您有同样感受的人而创建的 :)
是的,它非常完美可以混合 WebForms 和 ASP.NET MVC< /a>
ASP.NET MVC was created exactly for people who feel the way you do :)
Yes, it's perfectly possible to mix WebForms and ASP.NET MVC
是的,有些人不喜欢通常被称为“泄漏”的抽象,即 WebForms。 它试图将无状态浏览器请求变成类似于有状态表单应用程序的野兽,但并不总是成功,而且通常不优雅(大的视图状态隐藏字段、损坏的后退按钮功能、依赖 javascript 进行简单导航)。
这是 Microsoft 开发其 MVC 实现的一个重要原因。 它为您提供了一个“本机”Web 界面,没有抽象,同时维护一些帮助程序(它实际上称为帮助程序)。 在 MVC 之前,您还可以在 ASP.NET 上编写自己的非 Web 表单应用程序,这只是意味着更多的工作(我个人使用基于 HTTPHandler 构建的自己自制的系统来提供 RESTful url 和非 Web 表单交互) MVC 提供官方替代方案之前一年)
Yes, some people dislike the often called "leaky" abstraction that is WebForms. It attempts to turn stateless browser requests into a beast resembling a stateful form application, not always successful and usually not gracefully (large viewstate hidden fields, broken back button functionality, reliance on javascript for simple navigation).
That's a big reason why Microsoft developed its MVC implimentation. It gives you a "native" web interface, without the abstraction, while maintaining some helpers (which it actually calls helpers). Prior to MVC it was also possible to write your own non-webforms application on ASP.NET, it just meant more work (I personally was using my own home-brewed system built on HTTPHandler to provide RESTful urls and non-webform interaction for about a year before MVC provided an official alternative)
我从经典的 asp 和 php 转向了 .net。 起初这很困难。 我一直认为我可以在经典的 asp/php 中更快地完成工作,并且我的结果会更加干净和轻量。
回答你的问题:
是的(花了一段时间)
否(不知道为什么我从来没有被它困惑过,因为很多人都这样)
是的(但你不需要使用它们)
现在“回到”asp.net。 net MVC 我觉得我可以在网络表单中更轻松地做事情。 不过我已经开始掌握它的窍门了。 一切都回到了原点,但更好了。
正如许多人指出的那样,如果您还没有尝试过,您可能会更喜欢 asp.net MVC。
I went from classic asp and php to .net. At first it was difficult. I kept thinking that I could do things much faster in classic asp/php and that my results would be much cleaner and lightweight.
To answer your questions:
Yes (it took a while)
No (Not sure why I was never confused by it since a lot of people are)
Yes (but you don't need to use them)
Now going "back" to asp.net MVC I feel I can do things much easier in webforms. I'm starting to get the hang of it though. It's all come full circle but better.
As many pointed out, you might like asp.net MVC better if you haven't tried it already.
您是否熟练使用 System.Web.UI.* 控件?
您不会对页面生命周期感到困惑吗?
您不觉得在每个页面上放置一个 SQLDataSource 会产生难以维护的代码吗?
采用 MVC 方式有时会令人失望。 像分页和排序这样显而易见的东西需要重新发明(开源的东西通常不能满足您的所有需求)。 更重要的是,如果您不知道自己在做什么并且没有很好地组织起来,MVC 项目很容易变得一团糟。 但在专业人士手中——MVC就是一个核武器。
当心。 :)
Do you proficently use System.Web.UI.* controls?
Don't you get confused by the page lifecycle?
Don't you feel like that putting a SQLDataSource on each page produces unmaintainable code?
Going MVC way is dissapointing sometimes. The obvious stuff like paging and sorting needs to get reinvented (open source stuff usually doesn't fits all your needs). Even more important - MVC project can easily become a real mess if you don't know what you are doing and not keeping it well organized. But in hands of professional - MVC is a nuclear weapon.
Be careful. :)
这有点像 winforms 的东西,不过……提供一些更高层次的抽象来尝试让它看起来不像是在为 Web 开发。 您对 Web 开发了解得越多,您就越希望剥离这些抽象。 如果说 webforms 是自动变速箱,那么 ASP.NET MVC 就是变速杆。 它消除了很多抽象概念,让您能够轻松了解正在发生的事情。
That's kinda winforms thing, tho ... to provide some higher level abstractions to try and make it seem less like you're developing for the web. The more you learn about web development, the more you will want those abstractions stripped away. If webforms is an automatic transmission, then ASP.NET MVC is a stick shift. It strips away a lot of the abstractions and gives you gun metal access to what's going on.