In ASP.NET MVC (3.0 / Razor) do you prefer multiple views or conditional expressions in views? What for?

For my new web application, I am discussing the use of multiple views or conditional expressions in views.

In the sample script, various information will be displayed for authenticated users who have not authenticated. This could be solved in several ways.

  • In the controller, check IsAuthenticated and return a view based on this
  • In the view, check IsAuthenticated and show blocks of information based on this.

Pluses of several views: A smaller, less complex view - there is no logic in the view nearby

Pluses of individual views: fewer view files to support

The obvious disadvantages are the opposites of the pros: more files to support or more complex view files.

What do you prefer? What for? Any pros and cons that I have not outlined here?

Update: Suppose each view uses a layout page and partial views to abstract explicitly repeating code.

+5
source share
4 answers

, . , PG . , , , ..

: http://ryanfarley.com/blog/archive/2004/04/30/570.aspx

:

.
,

Partials:

  • - .
  • - .
  • .
  • , .

, , , , , , , , . , , , , - , , . .

, . , .

+10

, , 2 . , . , (, ), . ,

+1

, "if x display y". , - . html .

, , .

+1

I would say, start with one view ... then depending on how complex the difference between authenticated and unverified views is, you can create multiple views.

0
source

All Articles