Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7869839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:26:38+00:00 2026-06-03T01:26:38+00:00

In clean MVC, I would gather the data from the database and pass it

  • 0

In clean MVC, I would gather the data from the database and pass it over to the view to be rendered.

Even if the view logic chooses not to render some elements. Which raises the following question:

Is is clean to prepare a container with all the database queries, but only fetch the data from within the view, if and when the view starts to iterate this container (it’s iterable), instead of fetching the data “in the controller”?

Addendum

The container I’m passing over to the view is “kind of” a model, let’s call it ExpensiveObjectProvider. The data just has not yet been fetched from the database when this container is passed to the view.

The objects encapsulated by the container could be expensive. The only reason I see to still do it in the controller is error handling (in case of an error with the database query, connectivity problems, etc). Do you think it would be a good trade-off to prefetch the first 1-2-3 objects from the database in the controller, then pass over the container to the view (if no exception occures) and let the view consume the prefetched data and fetch new items as the container is iterated?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:26:40+00:00Added an answer on June 3, 2026 at 1:26 am

    Typically database code does not go into the view, it will be in the model or a DAO the model depends on. Logic in the view will be hard to test, and very messy if database accessing code is in it too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to take some data from the database and arrange it into rows
Executor seems like a clean abstraction. When would you want to use Thread directly
I'm trying to clean-up after an exception, and I'm not sure how to handle
I had a clean working directory and brought in a clone from a Git
How do I clean the installed java programs from the Blackberry simulator?
I'm still not totally clear on why I would need to build custom action
For an upcoming project, I am looking into MVP as an option over MVC.
I am upgrading my site from some old spaghetti coding to some nice, clean
I’m aware that not everyone uses a thorough architecture when developing an MVC application
I have started using Ninject 2 (downloaded from Github yesterday including the MVC extension

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.