Raam Kumar
Raam Kumar

Reputation: 127

Is it okay for Controllers to get data from View? MVC

I'm working on an application and I have grid of items (say files) displayed. I'm using a MVC concept where

I have requirement where the user may select a number of files, and perform an action. After the action has been done, a different file should be selected. This selection is based on the order of which user sees the files (e.g. select the next applicable row). That logic is still backend related but it depends on the order shown in the UI. Hence I'm trying to accomplish this in the controller method that's performing said action.

So I'm wondering if the sorting and selection should be stored in the Model instead, and the UI should be thinner (less logic). Because right now I'm finding it a bit weird for the Controller to call the UI to fetch the visible list order. What do you guys think?

Upvotes: 1

Views: 16

Answers (1)

Matt TechniQues
Matt TechniQues

Reputation: 26

I believe that this depends on what you want to achieve. In my opinion, I usually go towards using Passive View. As described in the article, it makes sure that the responsibility of the View is to render whatever the Controller feeds it. So, to relate it to your question, I think it is ok to do all data manipulation in the model. This will also increase the testability of your view

Upvotes: 1

Related Questions