Is fetching HTML directly from the model (MVC) a good idea?

After looking at examples and tutorials for some MVC libraries for web development on the Internet, I found that many of them build HTML directly in the code of the Model class, and then Controller simply sends it to a view that simply displays it. Although this makes Controller and View very simple and clean, I find this to be the wrong approach. IMHO, the model should simply retrieve data without having any presentation logic in it. The controller must pass this data to the view, and the View will contain code that iterates through it and generates the final HTML.

I think that's right, or did I miss some important point here?

+3
source share
3 answers

The presentation logic is split between the view (for the most part) and the controller. The model should not relate to presentation logic.

If so, you have no separation of concerns. This is not inherently bad, but you are losing sight of the benefits of separating presentation and business logic. So no, this is not a good idea.

Speaking of this, there are elements of presentation logic that can fall into the model. Think about cms. Ideally, you would have all the data labeled, say, xml, on which you would apply the template for its delivery. But the data and the template are stored in the model. So what is a presentation, and what is it?

There are gray areas, but in most cases it is easy to separate presentation and business logic.

+3
source

. , , HTML . html-.

+2

Is fetching HTML directly from Model (MVC) a good idea?

My gut instinct would say no. Interrupts the concept of separation of problems.

+1
source

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


All Articles