MVC: Are Models and Entity objects separate concepts?

好久不见. 提交于 2019-12-03 14:48:34

Yes!

My money is on the latter, since this would allow models to act independently

You don't want to bind your view to an Entity, because if the view also needs some other piece of data, you would have to it to your Entity. The model is entirely supportive of the view, and is concerned with supporting that view and nothing else.

For example, you show a list of your entities, what other data might you need? Current page number? Total number of pages? A custom message to be displayed?

This is why you should bind to a model, which you can freely add data items to as you need to.

Update

Here is an explanation of MVC in action...

The controller gets all of the data required for the request and puts it into the model. It then passes the model to the view.

The view then deals with the layout of the data in the model.

Each Model can be one entity that contains some methods to control and use its data.
Is it enough?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!