1

I reviewed some examples about MVC ASP.NET and all of them use the inline coding method.

Is there a big reason to use this method and ignore my preferred code behind method?

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Atta
  • 327
  • 1
  • 5
  • 16

3 Answers3

3

A nice quote from Derek Whittacker. Couldn't but it better myself

Also refer to this identical Q on SO

"In standard Asp.net WebForms development the CodeBehind was meant to act as a page controller, but over the years it has turned more into a dumping ground for all sorts of evil code (ie business logic). It is this nasty, ugly code that has given (in part) WebForms a bad image. By continuing to use your code behind in MVC all you are really doing is taking an old nasty technique and applying it to new framework and in turn removing one of the great advantages of MVC.

Part of the beauty of the MVC pattern (notice I said pattern, not framework) is that it helps to enforce Separations of Concerns by pushing logic out of your view and into your controllers."

Community
  • 1
  • 1
redsquare
  • 78,161
  • 20
  • 151
  • 159
  • Hi, what's you idea about this question: http://stackoverflow.com/questions/390693/does-anyone-beside-me-just-not-get-aspnet-mvc , I am so confused, because this question got 21 plus votes to now but I got -4 on the same. – Atta Dec 24 '08 at 22:16
1

I think the main reason for this is that there really shouldn't be much logic there since it's only logic related to the view. When there's not much logic my opinion is that it reads better using the inline method. However if there was a view with lot's of loops and such using the code behind is certainly a viable option in my opinion.

Patrik Hägne
  • 16,751
  • 5
  • 52
  • 60
0

In Scott Gu's recent blog about the MVC Release Candidate, they are having views not have code behind by default, which may be a reason you don't see that in samples.

NikolaiDante
  • 18,469
  • 14
  • 77
  • 117