views:

146

answers:

3

I'm surprised this hasn't been asked before...or maybe I just don't see it.

Anyway, I'm finally straying from the comfort of ASP.NET Web Forms and exploring the world of MVC2. I've done the nerdinner walk-through and it was fairly straightforward. Now I am getting a little more adventurous and building an MVC2 app on my own and would like to know if there are some common pitfalls that others can attest to.

Please consider my background as an ASP.NET Web Forms developer.

Thanks!

+3  A: 

Using server controls! It seems a lot of web forms guys assume server controls will work, place them all over their view and when they run it... Bamm! Errors all over the place.

Bigfellahull
A: 
  • Non-UI-related logic in views
  • WebForms View Engine (controversial, but after working with Spark I just cannot look at WebForms tag soup anymore)
  • Overly complex controller actions
Anton Gogolev
2 is pretty subjective. 3 is vague, what does overly complex mean?
jfar
+4  A: 

Base View Models

Base view models become god classes which end up being huge monstrosities. What happens is every widget that has to appear on every page ends up being in the base view model. Think of CNN.com or even Stackoverflow.com. You end up with a beast that touches so many different parts of the app. Even SO's case the base view model would have ads, related, login, messages, job ads, links. Thats pretty meaty.

The alternatives are messy, using the ViewData dictionary like a global variable or RenderAction/RenderPartial, but you avoid having your entire app being coupled to your base view model.

Heavy Base Controllers

Base Controllers also have a tendency to become heavy and tightly coupled to a lot of pieces. Most of the time code you throw in your base controller should be in its own action attribute.

Not Exploring MVC Contrib

MVC Contrib is an unbelievable awesome resource for solving common MVC problems. Even simply looking over MVC Contrib will give you tons of ideas and techniques that make developing MVC sites easier.

jfar