Is it right to get model data in a view or just in a controller?

I have an MVC application, and as a rule I get everything I need from the controller to view it. But when my views are nested inside other views, the pain is to redirect these variables to a nested view.

Is this true, or should I allow my partial / fragments nested in my views to retrieve data from the Model?

As an example, I have a list of states that I use in several nested parts / fragments. I need to pass this list through my views every time I want to use them only on nested particles / fragments in these views. He seems to be prone to error, and he feels not very DRY.

+3
source share
4 answers

This is absolutely true for View to directly read from the model.

Take a look at the Wikipedia article or Martin Fowler’s photo: http://martinfowler.com/eaaCatalog/modelViewController.html

+3
source

The view should never have direct access to the Model. In fact, the whole MVC paradigm is that each component is loosely coupled to the other. Thus, you can easily change our models or views. You cannot do this if you put the model code in your view.

. . "Fat Models, Skinny Controllers", , , .

, . MVC . , , , .

+3

MVC (), "" . " READY".

- : http://en.wikipedia.org/wiki/Presentation-abstraction-control

:

  • MVC ( , ) , , )
  • , / ( ).
0

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

, MVC , , . , () , .

0
source

Source: https://habr.com/ru/post/1781725/


All Articles