U
U
Uncle Seryozha2016-07-19 19:02:49
ASP.NET
Uncle Seryozha, 2016-07-19 19:02:49

What is the correct way to implement views in ASP.NET MVC?

There is a web application in which there are a heap of different pages. Many pages differ only in classes for different elements. For example, , .page-fixed, .has-gridstack etc. I have 2 options:

  1. Basically layout'e create a bunch of conditions (ex: if(ViewBag.NoSidebar){code}
  2. Create a bunch of different layouts.

Which of these options is best to use? Or perhaps it is better to use some other option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kovalsky, 2016-07-19
@dmitryKovalskiy

Forget about ViewBag forever - this is a tool to drag a message line into the view and that's it. Building program logic on it is a below average idea. Things like NoSidebar should be handled via CSS, or at least via client-side logic. Oddly enough, these are two very powerful tools that allow you not to fence the garden from views and layout. Decide on the architecture of the application. You say - a bunch of pages, do you get a bunch of controller methods or a bunch of controllers? Or are you replacing views with program logic? Where did the pile of pages come from? It is possible that this whole zoo should be grouped into complex Views containing PartialViews based on ornate models. If you have a lot of controllers, then maybe it's time to include regions and rivet your own layouts under them within the logic of the region.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question