tags:

views:

711

answers:

4

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?

+1  A: 

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
A: 

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.

DeletedAccount
+3  A: 

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."

redsquare
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.
Ata
A: 

Dear redsquare, Derek's sound is good but I can show you a page that all of DataAccess and Business methods is a another layer, but the view is full of HTML fields (ASP.Net Components) and it's codes to view them. Notice that all of heavy code that I told you is only for view (UI Layer). This heavy code is too complex to place in line code. For small websites or web application, inline code is good but for big website or web application, I think it is not a good solution.

Ata
This is a comment, not an answer.
Geoffrey Chetwood
Ata, for every aspx page with code behind done well there was a million done badly. The mvc way encourages better separation which can only be seen as a positive. Can you enlighten me on what you mean by 'heavy' code. Maybe give an example of this and we can tell you how this is done 'better' in mvc
redsquare
redsquare, I shall be so glad if you help me. I can't place my code here because is too long. please get me an email to send you an example (one page and its behind code of my web application). I will place the result of your help here.
Ata
Dear Rich B, Sorry, MY entry length was too big to fit in a comment. You edited my question title that means, developers MUST use inline coding, but my question is not this.
Ata
@ata: you can use helpers to encapsulate common UI tasks to reduce inline code. See for example http://haacked.com/archive/2008/05/03/code-based-repeater-for-asp.net-mvc.aspx
Mauricio Scheffer