我应该迁移到ASP。净MVC吗?

时间:2022-09-11 10:32:04

I just listened to the * team's 17th podcast, and they talked so highly of ASP.NET MVC that I decided to check it out.

我刚刚听了* team的第17播客,他们对ASP评价很高。我决定去看看。

But first, I want to be sure it's worth it. I already created a base web application (for other developers to build on) for a project that's starting in a few days and wanted to know, based on your experience, if I should take the time to learn the basics of MVC and re-create the base web application with this model.

但首先,我想确定它是值得的。我已经创建了一个基本的web应用程序(用于其他开发人员构建)一个项目开始的几天,想知道,根据你的经验,如果我应该花时间学习基本的MVC和重建的基本web应用程序模型。

Are there really big pros that'd make it worthwhile?

真的有大的专业人士会让它值得吗?

EDIT: It's not an existing project, it's a project about to start, so if I'm going to do it it should be now...

编辑:这不是一个现有的项目,它是一个即将开始的项目,所以如果我要做它,它应该是现在……


I just found this

我只是发现了这个

It does not, however, use the existing post-back model for interactions back to the server. Instead, you'll route all end-user interactions to a Controller class instead - which helps ensure clean separation of concerns and testability (it also means no viewstate or page lifecycle with MVC based views).

但是,它不会使用现有的后端模型来进行返回到服务器的交互。相反,您将把所有最终用户交互路由到一个Controller类——这有助于确保关注点和可测试性的清晰分离(它也意味着没有基于MVC的视图的viewstate或页面生命周期)。

How would that work? No viewstate? No events?

如何工作?没有视图状态?没有活动吗?

20 个解决方案

#1


65  

If you are quite happy with WebForms today, then maybe ASP.NET MVC isn't for you.

如果你对现在的网络表单很满意,那么也许是ASP吧。NET MVC不适合你。

I have been frustrated with WebForms for a really long time. I'm definitely not alone here. The smart-client, stateful abstraction over the web breaks down severely in complex scenarios. I happen to love HTML, Javascript, and CSS. WebForms tries to hide that from me. It also has some really complex solutions to problems that are really not that complex. Webforms is also inherently difficult to test, and while you can use MVP, it's not a great solution for a web environment...(compared to MVC).

我对WebForms感到沮丧已经有很长一段时间了。我绝对不是一个人。web上的智能客户端、有状态抽象在复杂场景中会严重崩溃。我碰巧喜欢HTML、Javascript和CSS。WebForms试图向我隐瞒这一点。它也有一些非常复杂的解决方案来解决那些不那么复杂的问题。web表单本身也很难测试,虽然您可以使用MVP,但它不是web环境的一个很好的解决方案……(MVC)相比。

MVC will appeal to you if... - you want more control over your HTML - want a seamless ajax experience like every other platform has - want testability through-and-through - want meaningful URLs - HATE dealing with postback & viewstate issues

如果…MVC会吸引你。你想要对你的HTML有更多的控制——想要一个无缝的ajax体验,就像所有其他平台一样——想要通过和通过——想要有意义的url——讨厌处理postback & viewstate问题。

And as for the framework being Preview 5, it is quite stable, the design is mostly there, and upgrading is not difficult. I started an app on Preview 1 and have upgraded within a few hours of the newest preview being available.

而对于框架的预览5,它是相当稳定的,设计大部分在那里,并且升级并不困难。我在Preview 1上启动了一个应用程序,并在最新的预览版本发布后的几个小时内进行了升级。

#2


31  

It's important to keep in mind that MVC and WebForms are not competing, and one is not better than the other. They are simply different tools. Most people seem to approach MVC vs WebForms as "one must be a better hammer than the other". That is wrong. One is a hammer, the other is a screwdriver. Both are used in the process of putting things together, but have different strengths and weaknesses.

重要的是要记住,MVC和WebForms并不是相互竞争的,一个也不比另一个好。它们只是不同的工具。大多数人似乎把MVC和WebForms看成是“一个必须比另一个更好的锤子”。这是错误的。一个是锤子,一个是螺丝刀。两者都被用于将事物放在一起的过程中,但是有不同的优缺点。

If one left you with a bad taste, you were probably trying to use a screwdriver to pound a nail. Certain problems are cumbersome with WebForms that become elegant and simple with MVC, and vice-versa.

如果其中一个给你留下了不好的印象,你可能是想用螺丝刀敲钉子。对于使用MVC变得优雅和简单的WebForms来说,某些问题非常麻烦,反之亦然。

#3


12  

I have used ASP.NET MVC (I even wrote a HTTPModule that lets you define the routes in web.config), and I still get a bitter taste in my mouth about it.

我已经使用ASP。NET MVC(我甚至编写了一个HTTPModule,允许您在web.config中定义路由),我仍然对它耿耿于怀。

It seems like a giant step backwards in organization and productivity. Maybe its not for some, but I've got webforms figured out, and they present no challenge to me as far as making them maintainable.

这似乎是组织和生产力的巨大倒退。也许对一些人来说不是这样的,但我已经弄清楚了webforms,它们在使它们可维护性方面对我来说并没有什么挑战。

That, and I don't endorse the current "TEST EVERYTHING" fad...

我不赞成现在的“测试一切”风潮……

#4


11  

ASP.NET MVC basically allows you to separate the responsibility of different sections of the code. This enable you to test your application. You can test your Views, Routes etc. It also does speed up the application since now there is no ViewState or Postback.

ASP。NET MVC允许您分离代码的不同部分的职责。这使您能够测试应用程序。您可以测试您的视图、路由等。它还可以加速应用程序,因为现在没有ViewState或回发。

BUT, there are also disadvantages. Since, you are no using WebForms you cannot use any ASP.NET control. It means if you want to create a GridView you will be running a for loop and create the table manually. If you want to use the ASP.NET Wizard in MVC then you will have to create on your own.

但是,也有缺点。因为您没有使用WebForms,所以您不能使用任何ASP。网络控制。这意味着如果您想创建一个GridView,您将运行一个for循环并手动创建表。如果你想使用ASP。MVC中的NET向导,然后你必须自己创建。

It is a nice framework if you are sick and tired of ASP.NET webform and want to perform everything on your own. But you need to keep in mind that would you benefit from creating all the stuff again or not?

如果您厌倦了ASP,这是一个很好的框架。NET webform,并希望自己执行所有内容。但是你需要记住,你是否会从重新创造这些东西中获益?

In general I prefer Webforms framework due to the rich suite of controls and the automatic plumbing.

总的来说,我更喜欢Webforms框架,因为它有丰富的控件和自动管道系统。

#5


9  

I would create a test site first, and see what the team thinks, but for me I wouldn't go back to WebForms after using MVC.

我将首先创建一个测试站点,并查看团队的想法,但是对于我来说,我不会在使用MVC之后返回到WebForms。

Some people don't like code mixed with HTML, and I can understand that, but I far prefer the flexibility over things like Page Lifecycle, rendering HTML and biggy for me - no viewstate cruft embedded in the page source.

有些人不喜欢将代码与HTML混合在一起,我可以理解这一点,但相对于页面生命周期、呈现HTML和对我来说更喜欢灵活性——没有嵌入在页面源代码中的viewstate cruft。

Some people prefer MVC for better testibility, but personally most of my code is in the middle layer and easily tested anyway...

有些人更喜欢MVC以获得更好的可验证性,但就我个人而言,我的大部分代码都在中间层,而且无论如何都很容易测试……

#6


6  

@Jonathan Holland I saw that you were voted down, but that is a VERY VALID point. I have been reading some posts around the intertubes where people seem to be confusing ASP.NET MVC the framework and MVC the pattern.

@Jonathan Holland我看到你被否决了,但这是一个非常有效的观点。我一直在网上看到一些文章,人们似乎对ASP很困惑。NET MVC框架和MVC模式。

MVC in of itself is a DESIGN PATTERN. If all you are looking for is a "separation of concerns" then you can certainly achieve that with webforms. Personally, I am a big fan of the MVP pattern in a standard n-tier environment.

MVC本身就是一个设计模式。如果您所寻找的只是“关注点分离”,那么您当然可以通过webforms实现这一点。就个人而言,我是标准n层环境中MVP模式的忠实粉丝。

If you really want TOTAL control of your mark-up in the ASP.NET world, then MVC the ramework is for you.

如果你真的想要在ASP中完全控制你的标记。NET world,那么MVC模式就是为您服务的。

#7


6  

@Juan Manuel Did you ever work in classic ASP? When you had to program all of your own events and "viewstatish" items (like a dropdown recalling its selected value after form submission)?

@Juan Manuel你曾经在经典ASP中工作过吗?当您必须为您自己的所有事件和“viewstatish”项编写程序时(比如在提交表单后回顾其选定值的下拉菜单)?

If so, then ASP.NET MVC will not feel that awkward off the bat. I would check out Rob Conery's Awesome Series "MVC Storefront" where he has been walking through the framework and building each expected component for a storefront site. It's really impressive and easy to follow along (catching up is tough because Rob has been reall active and posted A LOT in that series).

如果是这样,那么ASP。NET MVC不会立刻感到尴尬。我想去看看Rob Conery的《MVC店面》系列,他一直在浏览框架,并为店面站点构建每个预期的组件。这真的很让人印象深刻,也很容易跟进(追上来很困难,因为罗伯在这个系列里一直都很活跃,而且发了很多帖子)。

Personally, and quite contrary to Jeff Atwood's feelings on the topic, I rather liked the webform model. It was totally different than the vbscript/classic ASP days for sure but keeping viewstate in check and writing your own CSS friendly controls was enjoyable, actually.

就我个人而言,与杰夫·阿特伍德对这个话题的看法截然相反,我更喜欢webform模型。它与vbscript/classic ASP完全不同,但是保持viewstate处于受控状态并编写自己的CSS友好控件实际上是很有趣的。

Then again, note that I said "liked". ASP.NET MVC is really awesome and more alike other web technologies out there. It certainly is easier to shift from ASP.NET MVC to RAILS if you like to or need to work on multiple platforms. And while, yes, it is very stable obviously (this very site), if your company disallows "beta" software of any color; implementing it into production at the this time might be an issue.

然后,注意我说的“喜欢”。ASP。NET MVC非常棒,和其他web技术一样。它当然更容易从ASP转移。NET MVC到RAILS,如果您喜欢或需要在多个平台上工作。当然,如果你的公司不允许任何颜色的“beta”软件,它显然是非常稳定的。此时将其实现到生产中可能是一个问题。

#8


5  

If you are a professional ASP.NET developer, and have some time to spare on learning new stuff, I would certainly recommend that you spend some time trying out ASP.NET MVC. It may not be the solution to all your problems, and there are lots of projects that may benefit more from a traditional webform implementation, but while trying to figure out MVC you will certainly learn a lot, and it might bring up lots of ideas that you can apply on your job.

如果你是一个专业的ASP。NET developer,并且有一些时间来学习新的东西,我当然建议您花一些时间尝试ASP。净MVC。它可能不是解决你所有的问题,有很多的项目,可以造福更多从传统webform实现,虽然试图找出MVC你肯定会学到很多东西,可能会带来很多的想法,您可以应用在你的工作。

One good thing that I noticed while going through many blog posts and video tutorials while trying to develop a MVC pet-project is that most of them follow the current best practices (TDD, IoC, Dependency Injection, and to a lower extent POCO), plus a lot of JQuery to make the experience more interesting for the user, and that is stuff that I can apply on my current webform apps, and that I wasn't exposed in such depth before.

一件好事,我注意到,经历许多博客和视频教程在试图开发一个MVC宠物计划是,他们中的大多数遵循当前的最佳实践(TDD、国际奥委会、依赖注入和在一个较低的程度上略),加上大量的JQuery为用户体验更有趣,这东西我可以应用在当前webform应用,而我并没有暴露在这样的深度。

The ASP.NET MVC way of doing things is so different from webforms that it will shake up a bit your mind, and that for a developer is very good!

ASP。NET MVC做事的方式与webforms是如此的不同,它会让你产生一些想法,对于开发人员来说是非常好的!

OTOH for a total beginner to web development I think MVC is definitely a better start because it offers a good design pattern out of the box and is closer to the way that the web really works (HTML is stateless, after all). On MVC you decide on every byte that goes back and forth on the wire (at least while you don't go crazy on html helpers). Once the guy gets that, he or she will be better equipped to move to the "artificial" facilities provided by ASP.NET webforms and server controls.

OTOH对于一个完全入门的web开发来说,我认为MVC绝对是一个更好的开始,因为它提供了一种良好的开箱即用的设计模式,并且更接近于web真正的工作方式(毕竟HTML是无状态的)。在MVC中,您决定在连接上来回切换的每一个字节(至少在使用html helper时,您不会发疯)。一旦这个人得到这个,他或她将会更好地装备到ASP提供的“人工”设施。NET webforms和服务器控件。

#9


5  

If you like to use server controls which do a lot of work for you, you will NOT like MVC because you will need to do a lot of hand coding in MVC. If you like the GridView, expect to write one yourself or use someone else's.

如果您喜欢使用为您做大量工作的服务器控件,您将不会喜欢MVC,因为您将需要在MVC中做大量手工编码。如果你喜欢GridView,你可以自己写一个或者用别人的。

MVC is not for everyone, specially if you're not into unit testing the GUI part. If you're comfortable with web forms, stay with it. Web Forms 4.0 will fix some of the current shortcomings like the ID's which are automatically assigned by ASP.NET. You will have control of these in the next version.

MVC并不适合所有人,特别是如果您不喜欢单元测试GUI部分的话。如果你喜欢网络表单,那就继续。Web Forms 4.0将修复一些当前的缺点,比如ASP.NET自动分配的ID。在下一个版本中,您将控制这些内容。

#10


4  

Unless the developers you are working with are familiar with MVC pattern I wouldn't. At a minimum I'd talk with them first before making such a big change.

除非与您合作的开发人员熟悉MVC模式,否则我不会这么做。在做出如此大的改变之前,我至少得先和他们谈谈。

#11


4  

I'm trying to make that same decision about ASP.NET MVC, Juan Manuel. I'm now waiting for the right bite-sized project to come along with which I can experiment. If the experiment goes well--my gut says it will--then I'm going to architect my new large projects around the framework.

我正试图对ASP做同样的决定。净MVC,胡安•曼努埃尔•。我现在正在等待合适的小型项目,我可以进行实验。如果实验进展顺利——我的直觉告诉我它会成功——那么我将围绕这个框架设计我的新大型项目。

With ASP.NET MVC you lose the viewstate/postback model of ASP.NET Web Forms. Without that abstraction, you work much more closely with the HTML and the HTTP POST and GET commands. I believe the UI programming is somewhat in the direction of classic ASP.

ASP。你失去了ASP的viewstate/postback模型。净Web表单。没有了抽象,您就可以更紧密地使用HTML和HTTP POST并获取命令。我认为UI编程在某种程度上是向经典ASP方向发展的。

With that inconvenience, comes a greater degree of control. I've very often found myself fighting the psuedo-session garbage of ASP.NET and the prospect of regaining complete control of the output HTML seems very refreshing.

这种不便带来了更大程度的控制。我经常发现自己在与ASP的psuedo会话垃圾作斗争。NET和恢复对输出HTML的完全控制的前景似乎非常令人振奋。

It's perhaps either the best--or the worst--of both worlds.

它可能是两个世界中最好的,也可能是最坏的。

#13


2  

I dont´t know ASP.NET MVC, but I am very familiar with MVC pattern. I don´t see another way to build professional applications without MVC. And it has to be MVC model 2, like Spring or Struts. By the way, how you people were building web applications without MVC? When you have a situation that some kind of validation is necessary on every request, as validating if user is authenticated, what is your solution? Some kind of include(validate.aspx) in every page?

我不´t知道ASP。NET MVC,但是我非常熟悉MVC模式。我觉得´t没有MVC构建专业的应用程序的另一种方法。它必须是MVC模型2,像Spring或Struts。顺便问一下,你们是怎么在没有MVC的情况下构建web应用的?当您遇到需要对每个请求进行某种验证的情况时,比如验证用户是否通过了身份验证,您的解决方案是什么?是不是每个页面都包含(validate.aspx) ?

Have you never heard of N-Tier development?

你没听说过n层开发吗?

#14


2  

Ajax, RAD (webforms with ajax are anti-RAD very often), COMPLETE CONTROL (without developing whole bunch of code and cycles). webforms are good only to bind some grid and such and not for anything else, and one more really important thing - performance. when u get stuck into the web forms hell u will switch on MVC sooner or later.

Ajax、RAD(带有Ajax的webforms通常是反RAD)、完整的控制(不需要开发大量代码和周期)。webforms只适合绑定一些网格,而不是其他任何东西,还有一个非常重要的东西——性能。当你陷入web表单时,你迟早会打开MVC。

#15


1  

I wouldn't recommend just making the switch on an existing project. Perhaps start a small "demo" project that the team can use to experiment with the technology and (if necessary) learn what they need to and demonstrate to management that it is worthwhile to make the switch. In the end, even the dev team might realize they aren't ready or it's not worth it.

我不建议只在现有的项目上进行转换。也许可以开始一个小的“演示”项目,团队可以使用这个项目来试验技术,并且(如果需要的话)了解他们需要什么,并向管理层证明,做这个转换是值得的。最后,即使是开发团队也可能意识到他们还没有准备好,或者不值得这样做。

Whatever you do, be sure to document it. Perhaps if you use a demo project, write a postmortem for future reference.

无论你做什么,一定要记录下来。也许,如果您使用一个演示项目,为将来的引用写一个事后剖析。

#16


1  

I dont´t know ASP.NET MVC, but I am very familiar with MVC pattern. I don´t see another way to build professional applications without MVC. And it has to be MVC model 2, like Spring or Struts. By the way, how you people were building web applications without MVC? When you have a situation that some kind of validation is necessary on every request, as validating if user is authenticated, what is your solution? Some kind of include(validate.aspx) in every page?

我不´t知道ASP。NET MVC,但是我非常熟悉MVC模式。我觉得´t没有MVC构建专业的应用程序的另一种方法。它必须是MVC模型2,像Spring或Struts。顺便问一下,你们是怎么在没有MVC的情况下构建web应用的?当您遇到需要对每个请求进行某种验证的情况时,比如验证用户是否通过了身份验证,您的解决方案是什么?是不是每个页面都包含(validate.aspx) ?

#17


1  

No, you shouldn't. Feel free to try it out on a new project, but a lot of people familiar with ASP.NET webforms aren't loving it yet, due to having to muck around with raw HTML + lots of different concepts + pretty slim pickings on documentation/tutorials.

不,你不能。可以在一个新项目上试用它,但是很多人都熟悉ASP。NET webforms还不喜欢它,因为它需要处理原始的HTML、大量不同的概念、文档和教程等。

#18


0  

Is the fact that ASP.net MVC is only in 'Preview 5' be a cause for concern when looking into it?

ASP.net MVC只在“Preview 5”中这一事实是否值得关注?

I know that * was created using it, but is there a chance that Microsoft could implement significant changes to the framework before it is officially out of beta/alpha/preview release?

我知道*是用它创建的,但是在beta/alpha/preview版本正式发布之前,微软有可能对框架进行重大修改吗?

#19


0  

If you are dead set on using an MVC framework, then I would rather set out to use Castle project's one...

如果您非常喜欢使用MVC框架,那么我宁愿使用Castle project的框架……

When that's said I personally think WebControls have a lot of advantages, like for instance being able to create event driven applications which have a stateful client and so on. Most of the arguments against WebControls are constructed because of lack of understanding the WebControl model etc. And not because they actually are truly bad...

我个人认为WebControls有很多优势,比如能够创建具有有状态客户端的事件驱动应用程序等等。大多数反对WebControls的理由是缺乏对WebControl模型的理解等等。

MVC is not a Silver Bullet, especially not Microsoft MVC...

MVC并不是万能的,尤其是Microsoft MVC…

#20


0  

I have seen some implementation of MVC framework where for the sake of testability, someone rendered the whole HTML in code. In this case the view is also a testable code. But I said, my friend, putting HTML in code is a maintenance nightmare and he said well I like everything compiled and tested. I didn't argue, but later found that he did put this HTML into resource files and the craziness continued...

我看到过一些MVC框架的实现,为了便于测试,有人用代码呈现了整个HTML。在这种情况下,视图也是可测试的代码。但是我说,我的朋友,把HTML放到代码中是一个维护噩梦,他说我喜欢所有编译和测试的东西。我没有争辩,但后来发现他确实把这个HTML放到了资源文件中,这种疯狂还在继续……

Little did he realized that the whole idea of separating View also solved the maintenance part. It outweighs the testability in some applications. We do not need to test the HTML design if we are using WYSWYG tool. WebForms are good for that reason.

他几乎没有意识到,分离视图的整个想法也解决了维护部分。它超过了某些应用程序的可测试性。如果我们使用WYSWYG工具,我们不需要测试HTML设计。网络表单就是因为这个原因。

I have often seen people abusing postback and viewstate and blaming it on the ASP .NET model.

我经常看到人们滥用postback和viewstate,并将其归咎于asp.net模型。

Remember the best webpages are still the .HTMLs and that's where is the Power of ASP .NET MVC.

记住,最好的网页仍然是。htmls,这就是asp.net MVC的强大之处。

#1


65  

If you are quite happy with WebForms today, then maybe ASP.NET MVC isn't for you.

如果你对现在的网络表单很满意,那么也许是ASP吧。NET MVC不适合你。

I have been frustrated with WebForms for a really long time. I'm definitely not alone here. The smart-client, stateful abstraction over the web breaks down severely in complex scenarios. I happen to love HTML, Javascript, and CSS. WebForms tries to hide that from me. It also has some really complex solutions to problems that are really not that complex. Webforms is also inherently difficult to test, and while you can use MVP, it's not a great solution for a web environment...(compared to MVC).

我对WebForms感到沮丧已经有很长一段时间了。我绝对不是一个人。web上的智能客户端、有状态抽象在复杂场景中会严重崩溃。我碰巧喜欢HTML、Javascript和CSS。WebForms试图向我隐瞒这一点。它也有一些非常复杂的解决方案来解决那些不那么复杂的问题。web表单本身也很难测试,虽然您可以使用MVP,但它不是web环境的一个很好的解决方案……(MVC)相比。

MVC will appeal to you if... - you want more control over your HTML - want a seamless ajax experience like every other platform has - want testability through-and-through - want meaningful URLs - HATE dealing with postback & viewstate issues

如果…MVC会吸引你。你想要对你的HTML有更多的控制——想要一个无缝的ajax体验,就像所有其他平台一样——想要通过和通过——想要有意义的url——讨厌处理postback & viewstate问题。

And as for the framework being Preview 5, it is quite stable, the design is mostly there, and upgrading is not difficult. I started an app on Preview 1 and have upgraded within a few hours of the newest preview being available.

而对于框架的预览5,它是相当稳定的,设计大部分在那里,并且升级并不困难。我在Preview 1上启动了一个应用程序,并在最新的预览版本发布后的几个小时内进行了升级。

#2


31  

It's important to keep in mind that MVC and WebForms are not competing, and one is not better than the other. They are simply different tools. Most people seem to approach MVC vs WebForms as "one must be a better hammer than the other". That is wrong. One is a hammer, the other is a screwdriver. Both are used in the process of putting things together, but have different strengths and weaknesses.

重要的是要记住,MVC和WebForms并不是相互竞争的,一个也不比另一个好。它们只是不同的工具。大多数人似乎把MVC和WebForms看成是“一个必须比另一个更好的锤子”。这是错误的。一个是锤子,一个是螺丝刀。两者都被用于将事物放在一起的过程中,但是有不同的优缺点。

If one left you with a bad taste, you were probably trying to use a screwdriver to pound a nail. Certain problems are cumbersome with WebForms that become elegant and simple with MVC, and vice-versa.

如果其中一个给你留下了不好的印象,你可能是想用螺丝刀敲钉子。对于使用MVC变得优雅和简单的WebForms来说,某些问题非常麻烦,反之亦然。

#3


12  

I have used ASP.NET MVC (I even wrote a HTTPModule that lets you define the routes in web.config), and I still get a bitter taste in my mouth about it.

我已经使用ASP。NET MVC(我甚至编写了一个HTTPModule,允许您在web.config中定义路由),我仍然对它耿耿于怀。

It seems like a giant step backwards in organization and productivity. Maybe its not for some, but I've got webforms figured out, and they present no challenge to me as far as making them maintainable.

这似乎是组织和生产力的巨大倒退。也许对一些人来说不是这样的,但我已经弄清楚了webforms,它们在使它们可维护性方面对我来说并没有什么挑战。

That, and I don't endorse the current "TEST EVERYTHING" fad...

我不赞成现在的“测试一切”风潮……

#4


11  

ASP.NET MVC basically allows you to separate the responsibility of different sections of the code. This enable you to test your application. You can test your Views, Routes etc. It also does speed up the application since now there is no ViewState or Postback.

ASP。NET MVC允许您分离代码的不同部分的职责。这使您能够测试应用程序。您可以测试您的视图、路由等。它还可以加速应用程序,因为现在没有ViewState或回发。

BUT, there are also disadvantages. Since, you are no using WebForms you cannot use any ASP.NET control. It means if you want to create a GridView you will be running a for loop and create the table manually. If you want to use the ASP.NET Wizard in MVC then you will have to create on your own.

但是,也有缺点。因为您没有使用WebForms,所以您不能使用任何ASP。网络控制。这意味着如果您想创建一个GridView,您将运行一个for循环并手动创建表。如果你想使用ASP。MVC中的NET向导,然后你必须自己创建。

It is a nice framework if you are sick and tired of ASP.NET webform and want to perform everything on your own. But you need to keep in mind that would you benefit from creating all the stuff again or not?

如果您厌倦了ASP,这是一个很好的框架。NET webform,并希望自己执行所有内容。但是你需要记住,你是否会从重新创造这些东西中获益?

In general I prefer Webforms framework due to the rich suite of controls and the automatic plumbing.

总的来说,我更喜欢Webforms框架,因为它有丰富的控件和自动管道系统。

#5


9  

I would create a test site first, and see what the team thinks, but for me I wouldn't go back to WebForms after using MVC.

我将首先创建一个测试站点,并查看团队的想法,但是对于我来说,我不会在使用MVC之后返回到WebForms。

Some people don't like code mixed with HTML, and I can understand that, but I far prefer the flexibility over things like Page Lifecycle, rendering HTML and biggy for me - no viewstate cruft embedded in the page source.

有些人不喜欢将代码与HTML混合在一起,我可以理解这一点,但相对于页面生命周期、呈现HTML和对我来说更喜欢灵活性——没有嵌入在页面源代码中的viewstate cruft。

Some people prefer MVC for better testibility, but personally most of my code is in the middle layer and easily tested anyway...

有些人更喜欢MVC以获得更好的可验证性,但就我个人而言,我的大部分代码都在中间层,而且无论如何都很容易测试……

#6


6  

@Jonathan Holland I saw that you were voted down, but that is a VERY VALID point. I have been reading some posts around the intertubes where people seem to be confusing ASP.NET MVC the framework and MVC the pattern.

@Jonathan Holland我看到你被否决了,但这是一个非常有效的观点。我一直在网上看到一些文章,人们似乎对ASP很困惑。NET MVC框架和MVC模式。

MVC in of itself is a DESIGN PATTERN. If all you are looking for is a "separation of concerns" then you can certainly achieve that with webforms. Personally, I am a big fan of the MVP pattern in a standard n-tier environment.

MVC本身就是一个设计模式。如果您所寻找的只是“关注点分离”,那么您当然可以通过webforms实现这一点。就个人而言,我是标准n层环境中MVP模式的忠实粉丝。

If you really want TOTAL control of your mark-up in the ASP.NET world, then MVC the ramework is for you.

如果你真的想要在ASP中完全控制你的标记。NET world,那么MVC模式就是为您服务的。

#7


6  

@Juan Manuel Did you ever work in classic ASP? When you had to program all of your own events and "viewstatish" items (like a dropdown recalling its selected value after form submission)?

@Juan Manuel你曾经在经典ASP中工作过吗?当您必须为您自己的所有事件和“viewstatish”项编写程序时(比如在提交表单后回顾其选定值的下拉菜单)?

If so, then ASP.NET MVC will not feel that awkward off the bat. I would check out Rob Conery's Awesome Series "MVC Storefront" where he has been walking through the framework and building each expected component for a storefront site. It's really impressive and easy to follow along (catching up is tough because Rob has been reall active and posted A LOT in that series).

如果是这样,那么ASP。NET MVC不会立刻感到尴尬。我想去看看Rob Conery的《MVC店面》系列,他一直在浏览框架,并为店面站点构建每个预期的组件。这真的很让人印象深刻,也很容易跟进(追上来很困难,因为罗伯在这个系列里一直都很活跃,而且发了很多帖子)。

Personally, and quite contrary to Jeff Atwood's feelings on the topic, I rather liked the webform model. It was totally different than the vbscript/classic ASP days for sure but keeping viewstate in check and writing your own CSS friendly controls was enjoyable, actually.

就我个人而言,与杰夫·阿特伍德对这个话题的看法截然相反,我更喜欢webform模型。它与vbscript/classic ASP完全不同,但是保持viewstate处于受控状态并编写自己的CSS友好控件实际上是很有趣的。

Then again, note that I said "liked". ASP.NET MVC is really awesome and more alike other web technologies out there. It certainly is easier to shift from ASP.NET MVC to RAILS if you like to or need to work on multiple platforms. And while, yes, it is very stable obviously (this very site), if your company disallows "beta" software of any color; implementing it into production at the this time might be an issue.

然后,注意我说的“喜欢”。ASP。NET MVC非常棒,和其他web技术一样。它当然更容易从ASP转移。NET MVC到RAILS,如果您喜欢或需要在多个平台上工作。当然,如果你的公司不允许任何颜色的“beta”软件,它显然是非常稳定的。此时将其实现到生产中可能是一个问题。

#8


5  

If you are a professional ASP.NET developer, and have some time to spare on learning new stuff, I would certainly recommend that you spend some time trying out ASP.NET MVC. It may not be the solution to all your problems, and there are lots of projects that may benefit more from a traditional webform implementation, but while trying to figure out MVC you will certainly learn a lot, and it might bring up lots of ideas that you can apply on your job.

如果你是一个专业的ASP。NET developer,并且有一些时间来学习新的东西,我当然建议您花一些时间尝试ASP。净MVC。它可能不是解决你所有的问题,有很多的项目,可以造福更多从传统webform实现,虽然试图找出MVC你肯定会学到很多东西,可能会带来很多的想法,您可以应用在你的工作。

One good thing that I noticed while going through many blog posts and video tutorials while trying to develop a MVC pet-project is that most of them follow the current best practices (TDD, IoC, Dependency Injection, and to a lower extent POCO), plus a lot of JQuery to make the experience more interesting for the user, and that is stuff that I can apply on my current webform apps, and that I wasn't exposed in such depth before.

一件好事,我注意到,经历许多博客和视频教程在试图开发一个MVC宠物计划是,他们中的大多数遵循当前的最佳实践(TDD、国际奥委会、依赖注入和在一个较低的程度上略),加上大量的JQuery为用户体验更有趣,这东西我可以应用在当前webform应用,而我并没有暴露在这样的深度。

The ASP.NET MVC way of doing things is so different from webforms that it will shake up a bit your mind, and that for a developer is very good!

ASP。NET MVC做事的方式与webforms是如此的不同,它会让你产生一些想法,对于开发人员来说是非常好的!

OTOH for a total beginner to web development I think MVC is definitely a better start because it offers a good design pattern out of the box and is closer to the way that the web really works (HTML is stateless, after all). On MVC you decide on every byte that goes back and forth on the wire (at least while you don't go crazy on html helpers). Once the guy gets that, he or she will be better equipped to move to the "artificial" facilities provided by ASP.NET webforms and server controls.

OTOH对于一个完全入门的web开发来说,我认为MVC绝对是一个更好的开始,因为它提供了一种良好的开箱即用的设计模式,并且更接近于web真正的工作方式(毕竟HTML是无状态的)。在MVC中,您决定在连接上来回切换的每一个字节(至少在使用html helper时,您不会发疯)。一旦这个人得到这个,他或她将会更好地装备到ASP提供的“人工”设施。NET webforms和服务器控件。

#9


5  

If you like to use server controls which do a lot of work for you, you will NOT like MVC because you will need to do a lot of hand coding in MVC. If you like the GridView, expect to write one yourself or use someone else's.

如果您喜欢使用为您做大量工作的服务器控件,您将不会喜欢MVC,因为您将需要在MVC中做大量手工编码。如果你喜欢GridView,你可以自己写一个或者用别人的。

MVC is not for everyone, specially if you're not into unit testing the GUI part. If you're comfortable with web forms, stay with it. Web Forms 4.0 will fix some of the current shortcomings like the ID's which are automatically assigned by ASP.NET. You will have control of these in the next version.

MVC并不适合所有人,特别是如果您不喜欢单元测试GUI部分的话。如果你喜欢网络表单,那就继续。Web Forms 4.0将修复一些当前的缺点,比如ASP.NET自动分配的ID。在下一个版本中,您将控制这些内容。

#10


4  

Unless the developers you are working with are familiar with MVC pattern I wouldn't. At a minimum I'd talk with them first before making such a big change.

除非与您合作的开发人员熟悉MVC模式,否则我不会这么做。在做出如此大的改变之前,我至少得先和他们谈谈。

#11


4  

I'm trying to make that same decision about ASP.NET MVC, Juan Manuel. I'm now waiting for the right bite-sized project to come along with which I can experiment. If the experiment goes well--my gut says it will--then I'm going to architect my new large projects around the framework.

我正试图对ASP做同样的决定。净MVC,胡安•曼努埃尔•。我现在正在等待合适的小型项目,我可以进行实验。如果实验进展顺利——我的直觉告诉我它会成功——那么我将围绕这个框架设计我的新大型项目。

With ASP.NET MVC you lose the viewstate/postback model of ASP.NET Web Forms. Without that abstraction, you work much more closely with the HTML and the HTTP POST and GET commands. I believe the UI programming is somewhat in the direction of classic ASP.

ASP。你失去了ASP的viewstate/postback模型。净Web表单。没有了抽象,您就可以更紧密地使用HTML和HTTP POST并获取命令。我认为UI编程在某种程度上是向经典ASP方向发展的。

With that inconvenience, comes a greater degree of control. I've very often found myself fighting the psuedo-session garbage of ASP.NET and the prospect of regaining complete control of the output HTML seems very refreshing.

这种不便带来了更大程度的控制。我经常发现自己在与ASP的psuedo会话垃圾作斗争。NET和恢复对输出HTML的完全控制的前景似乎非常令人振奋。

It's perhaps either the best--or the worst--of both worlds.

它可能是两个世界中最好的,也可能是最坏的。

#12


#13


2  

I dont´t know ASP.NET MVC, but I am very familiar with MVC pattern. I don´t see another way to build professional applications without MVC. And it has to be MVC model 2, like Spring or Struts. By the way, how you people were building web applications without MVC? When you have a situation that some kind of validation is necessary on every request, as validating if user is authenticated, what is your solution? Some kind of include(validate.aspx) in every page?

我不´t知道ASP。NET MVC,但是我非常熟悉MVC模式。我觉得´t没有MVC构建专业的应用程序的另一种方法。它必须是MVC模型2,像Spring或Struts。顺便问一下,你们是怎么在没有MVC的情况下构建web应用的?当您遇到需要对每个请求进行某种验证的情况时,比如验证用户是否通过了身份验证,您的解决方案是什么?是不是每个页面都包含(validate.aspx) ?

Have you never heard of N-Tier development?

你没听说过n层开发吗?

#14


2  

Ajax, RAD (webforms with ajax are anti-RAD very often), COMPLETE CONTROL (without developing whole bunch of code and cycles). webforms are good only to bind some grid and such and not for anything else, and one more really important thing - performance. when u get stuck into the web forms hell u will switch on MVC sooner or later.

Ajax、RAD(带有Ajax的webforms通常是反RAD)、完整的控制(不需要开发大量代码和周期)。webforms只适合绑定一些网格,而不是其他任何东西,还有一个非常重要的东西——性能。当你陷入web表单时,你迟早会打开MVC。

#15


1  

I wouldn't recommend just making the switch on an existing project. Perhaps start a small "demo" project that the team can use to experiment with the technology and (if necessary) learn what they need to and demonstrate to management that it is worthwhile to make the switch. In the end, even the dev team might realize they aren't ready or it's not worth it.

我不建议只在现有的项目上进行转换。也许可以开始一个小的“演示”项目,团队可以使用这个项目来试验技术,并且(如果需要的话)了解他们需要什么,并向管理层证明,做这个转换是值得的。最后,即使是开发团队也可能意识到他们还没有准备好,或者不值得这样做。

Whatever you do, be sure to document it. Perhaps if you use a demo project, write a postmortem for future reference.

无论你做什么,一定要记录下来。也许,如果您使用一个演示项目,为将来的引用写一个事后剖析。

#16


1  

I dont´t know ASP.NET MVC, but I am very familiar with MVC pattern. I don´t see another way to build professional applications without MVC. And it has to be MVC model 2, like Spring or Struts. By the way, how you people were building web applications without MVC? When you have a situation that some kind of validation is necessary on every request, as validating if user is authenticated, what is your solution? Some kind of include(validate.aspx) in every page?

我不´t知道ASP。NET MVC,但是我非常熟悉MVC模式。我觉得´t没有MVC构建专业的应用程序的另一种方法。它必须是MVC模型2,像Spring或Struts。顺便问一下,你们是怎么在没有MVC的情况下构建web应用的?当您遇到需要对每个请求进行某种验证的情况时,比如验证用户是否通过了身份验证,您的解决方案是什么?是不是每个页面都包含(validate.aspx) ?

#17


1  

No, you shouldn't. Feel free to try it out on a new project, but a lot of people familiar with ASP.NET webforms aren't loving it yet, due to having to muck around with raw HTML + lots of different concepts + pretty slim pickings on documentation/tutorials.

不,你不能。可以在一个新项目上试用它,但是很多人都熟悉ASP。NET webforms还不喜欢它,因为它需要处理原始的HTML、大量不同的概念、文档和教程等。

#18


0  

Is the fact that ASP.net MVC is only in 'Preview 5' be a cause for concern when looking into it?

ASP.net MVC只在“Preview 5”中这一事实是否值得关注?

I know that * was created using it, but is there a chance that Microsoft could implement significant changes to the framework before it is officially out of beta/alpha/preview release?

我知道*是用它创建的,但是在beta/alpha/preview版本正式发布之前,微软有可能对框架进行重大修改吗?

#19


0  

If you are dead set on using an MVC framework, then I would rather set out to use Castle project's one...

如果您非常喜欢使用MVC框架,那么我宁愿使用Castle project的框架……

When that's said I personally think WebControls have a lot of advantages, like for instance being able to create event driven applications which have a stateful client and so on. Most of the arguments against WebControls are constructed because of lack of understanding the WebControl model etc. And not because they actually are truly bad...

我个人认为WebControls有很多优势,比如能够创建具有有状态客户端的事件驱动应用程序等等。大多数反对WebControls的理由是缺乏对WebControl模型的理解等等。

MVC is not a Silver Bullet, especially not Microsoft MVC...

MVC并不是万能的,尤其是Microsoft MVC…

#20


0  

I have seen some implementation of MVC framework where for the sake of testability, someone rendered the whole HTML in code. In this case the view is also a testable code. But I said, my friend, putting HTML in code is a maintenance nightmare and he said well I like everything compiled and tested. I didn't argue, but later found that he did put this HTML into resource files and the craziness continued...

我看到过一些MVC框架的实现,为了便于测试,有人用代码呈现了整个HTML。在这种情况下,视图也是可测试的代码。但是我说,我的朋友,把HTML放到代码中是一个维护噩梦,他说我喜欢所有编译和测试的东西。我没有争辩,但后来发现他确实把这个HTML放到了资源文件中,这种疯狂还在继续……

Little did he realized that the whole idea of separating View also solved the maintenance part. It outweighs the testability in some applications. We do not need to test the HTML design if we are using WYSWYG tool. WebForms are good for that reason.

他几乎没有意识到,分离视图的整个想法也解决了维护部分。它超过了某些应用程序的可测试性。如果我们使用WYSWYG工具,我们不需要测试HTML设计。网络表单就是因为这个原因。

I have often seen people abusing postback and viewstate and blaming it on the ASP .NET model.

我经常看到人们滥用postback和viewstate,并将其归咎于asp.net模型。

Remember the best webpages are still the .HTMLs and that's where is the Power of ASP .NET MVC.

记住,最好的网页仍然是。htmls,这就是asp.net MVC的强大之处。