0

Consider u have a big front page include ton of data from database (like new products,best products, latest posts, banners,sliders,etc) not only static views like header or something like that. related to this post it seems this is better to build a complex model and split page to small partial views. but what is wrong with this way that USE ACTIONS and split page like this:

@{
    ViewBag.Title = "Home";
}

@{Html.RenderAction("Header", "Home");}

@{Html.RenderAction("Sliders", "Home");}

@{Html.RenderAction("Specials", "Home");}

@{Html.RenderAction("Services", "Home");}

...

@{Html.RenderAction("Footer", "Home");}

so you no need to use a complex model.

EDIT: my main question is what is wrong with using actions in view instead partial views. in this way you no need to send a complex model to view and use its parts for partial views

Community
  • 1
  • 1
A.F.N
  • 179
  • 1
  • 12

1 Answers1

2

Using partial views makes the code easier to maintain, since partial views are by convention named with an underscore like "_PartialView"

this way you can easily see in your solution which views are partial and which are not.

How you want to implement them is a question of heart and experience most often, but always strive for best practice.

That is, try to code the way you think you want to read code when coming back after a long break from it, or how you want to find code written by others that you think is easy to understand fast.

The less cognitive strain, the better, whether the code is for you or someone else.

Mikael Puusaari
  • 768
  • 1
  • 8
  • 14
  • If you look in the solution explorer(in Visual studio) you can see all the Views, it is very easy to see an overview of the entire solution, which you don´t by going through perhaps thousands lines of code in one file it will be much easier to see in the solution explorer: MailHandler.cs than search the entire solution for an action This isn´t meant for tomorrow, but for always, you or someone else will be caretaking this code for ever – Mikael Puusaari May 24 '16 at 10:34