views:

1058

answers:

7

What are some helpful things that ASP.NET MVC developers could suggest that would help us ASP.NET WebForms developers to write better code/web apps?

I'm a WebForms guy but with all the new hype around MVC I'd value some comments on helpful tips, tricks and strategies that might be able to be used in a webforms app.

A: 

I'm also coming from webforms, but have been learning asp.net MVC since around preview 3.

I'm not exactly sure how to bring anything from MVC into webforms, they are two entirely different frameworks. I'm probably too new with it to understand how any of it could be applied to webforms, but right now it seems they have very little in common.

Some of the strengths of MVC are it's rigid structure on how you need to do things and where you put code. It also does away with the form runat=server and I believe does not promote the usage of any of the asp.net server controls (you need to write all the HTML yourself). That is pretty much the definition of webforms right there. MVC pretty much replaces webforms with it's own framework.

If you ever did Classic ASP or PHP, I would call ASP.net MVC a more structured framework for what people might do with those older scripting languages. It's kind of like the FuseBox framework, but even more structured and evolved.

metanaito
+2  A: 

I would recommend geting started by watching the screencasts on Microsoft's Learn site:

ASP.NET MVC Videos

There you will learn the differences between the WebForms postback model, and the way that MVC directly routes your URLs to Actions & Methods.

The second major difference is to remember that in ASP.NET MVC you do not use controls that do postbacks. It might feel a bit more like Classic ASP where code is inline on the page within server side blocks, but it is worth it. You will have full control over the HTML that is generated, and this is very good for things like Search Engine Optimization.

David P
+15  A: 

Something that occurred to me a while ago when learning about the new MVC framework, is that WebForms was, I think, an attempt at MVC in many ways. The markup and code-behind comprise View and Controller, and you're left to write your own Model.

This idea goes hand in hand with the important design considerations I gained from learning about MVC. The most important of which is solidifying the core domain of your system as a whole and making sure all common logic is defined at a level that is reusable within this domain. This is your Model, and I like to call the logic that lives at this level Domain Logic (I mix terms, I know). Your Model should be reusable across different applications (a main web/winforms app, winforms apps for utility and configuration, background processing services, web services, etc.). Your applications should stay very specific to their purpose: they consist of Presentation Logic (their views) and Application Logic (their controllers). Anything that crosses the line of needing to be used in other applications is easily classifiable as Domain Logic, and should not be part of the application code for any given application.

I hope that makes sense.

The gist of it is, even if you're not using a pure MVC framework or object model or whatever, this high level look at design can be applied with great effect. Isolate common logic in a domain layer that is reusable across applications and your applications are much easier to write and extend and maintain.

sliderhouserules
+5  A: 
  1. Forget about page life cycle
  2. There is no ViewState (by default that is)
  3. There are no postbacks
  4. You need to know the HTTP protocol basics (GET/POST). The same goes with HTML (DropDownList is actualy a tag)
korchev
+1  A: 

Some advices

  1. Don't use standard controls. Instead pay attention jQuery, MooTools.
  2. Use strongly typed Models
  3. It's good practice to use some IoC like Spring.NET
Alexander
A: 

Its like returning to first principles after experimenting heroics.

pokrate
A: 

the page that build by the asp.net mvc is very clear!