开发者

In what case would you prefer ASP.NET webforms over MVC? [duplicate]

开发者 https://www.devze.com 2023-01-13 15:03 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: What’s your choice for your next ASP.NET project: WebForms or MVC?
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

What’s your choice for your next ASP.NET project: WebForms or MVC?

Can you list some reasons that would make you use ASP.NET webforms for a new project, instead of MVC? I've hear开发者_开发技巧d a lot about the opposite, but not things that are done easier or better with webforms. I'm not talking about developer preferences here, but rather technology features and how they map to project features.


The only argument for WebForms is the need to design highly complex (read cluttered) interfaces with a whole lot of interconnected elements which in all or in part should react to changes in other elements.

A typical example would be some enterprise application (from SAP or smaller vendors). They usually have interfaces bordering madness. You'd have a hard time trying to synchronize the controls manually with JavaScript if you were on MVC. With WebForms it's by far easier.

Whether it is a good idea to build such interfaces is another matter entirely.


In WebForms element events trigger a page postback. They go to the same url and are processed in a unified manner. This is what makes the architecture very scalable.

With MVC to accomplish this you would have to set up a bunch of service urls to handle posts from different controls, then process those posts and update view models accordingly. This all involves a lot of trickery and juggling. Not that it is not doable - it is, but not on a big scale. This approach would not be scalable. Sooner or later you will arrive at the understanding you'd need to build your own framework in the direction of stateful object-oriented HTML/HTTP abstraction like WebForms.


A few things that could push me (back) towards WebForms:

  • I need to produce something that can be taken over by someone who isn't primarily a web application developer (say a WinForms programmer), and the app could substantially be maintained through Visual Studio's Forms Designer. The IDE support makes the development model closer to that of WinForms.
  • An app that needs to look Ajax-y but will be maintained by someone who won't learn JavaScript. I think things like the UpdatePanel (while horrible in so many ways) are actually pretty good for that scenario.
  • Possibly for some kind of demoware, again because of the IDE and ASP.NET AJAX. Fairly quick to knock up some reasonably smart screens without too much thinking.
  • I need a powerful CMS and need to stay within .NET. At this point it looks like there's better choice in WebForms than in MVC (though hopefully that's changing).
  • I'm working with a team who are already familiar with it and aren't going to learn MVC.

Of those, probably the CMS is the requirement I could think of right now that would actually make me use WebForms.


If you only know webforms MVC comes with a learning curve so you will need to spend quite some time training (or risk making serious security or performance errors)

You need a tiny little app NOW It probably is quicker to build a throw away mock application in webforms if you go for the anti-pattern. E.g. SqlDataSource, Logic in your code behinds etc.

Rich controls GridView is an excellent control, having sorting etc all built in for you with little code needed as long as your custom requirements are small.

Lack of web development experience Web forms is just easier. It takes more concerns off your plate. Much better for a newbie as its tough to go wrong.

Having said that, if you know what you are doing or have the time to learn and you want to build a long lasting site, MVC is soooo good. And more fun too.

I'll add that there is nothing really wrong with web forms. It's perfectly possible to build high performance app with it. It's just times have changed since it first came out and MVC has addressed those changes well.


Personally, i find MVC very good for admin-pages. because they usually have a load of tables, and are made for data input and editing. MVC is 'made' for those things, so it's going very fast making those pages.

webforms I use for more complex things, like the User-end of the site. the site i make shows courses people can take. the registering for a course is a 5 step procedure, which in MVC, I have no real idea how to do it. I'm sure it can be done in MVC but I think it's better/faster in webforms.

however in the end I do like MVC more. It feels so much cleaner to work with.


The only time i would consider going with Web Forms in a new project is if there was a component created for Web Forms that solved a specific problem that would be much harder to solve using MVC.


I can no longer see any advantage of Webforms over MVC, apart from some upskilling effort which should not be prohibitive.

[Originally I believe MVC wasn't compatible with webcontrols, so wishing to use Dundas chart control for example wasn't possible. That would have been a good argument for using webforms depending upon your requirements. But I believe this is no longer the case, and anyhow, you can include webforms in your MVC project as a worst case.]


It depends!

The difference between WebForms and MVC is if you can TDD and control the complete markup.

0

精彩评论

暂无评论...
验证码 换一张
取 消