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 359775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:25:33+00:00 2026-05-12T12:25:33+00:00

If a view needs to acces data from a model, do you think the

  • 0

If a view needs to acces data from a model, do you think the controller should:

a) pass the model to the view
b) pass the data of the model to the view
c) neither; it shouldn’t be the controllers concern. Let the view access the model directly to retrieve the data. Only let the controller give some parameters the view needs to filter the data from the model.
d) it depends on the situation.
e) none of the above, but […]

Thanks

After some debate in the comments to an answer that was deleted by the user, maybe this needs clarification. My view of the MVC architecture is biased towards that of the Zend Framework (php) in which an action in a controller by default has a default view assigned to it. So it’s not so much the model that dictates which view is approporiate, but rather the controller. Do you feel the model should dictate what view is appropriate? The only way I see fit to let the view be build based on a model, is by letting the controller pass the model to the view. Are there other techniques to let a view access a model without the controller being involved? Or is it perfectly fine to let a controller pass the model to a view, so that the view can be build based on the models attributes?

  • 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-05-12T12:25:33+00:00Added an answer on May 12, 2026 at 12:25 pm

    e) None of the above; pass in a view-optimised “ViewModel”.

    Example in ASP.NET MVC:-

    public ActionResult Details(int id)
    {
      Product p = ProductService.GetProductById(id);
    
      if(p == null) { return RedirectToAction("Index"); }
    
      ProductViewModel model = new ProductViewModel(p);
      return View(model);
    }
    

    both a) and b) “will do” subject to d). Never ever c).

    Typically, the ViewModel just encapsulates the Model (if nothing complicated is going on, your view could access the model directly via ProductViewModel.Product). If the view needs to do anything complicated with the Model however, it’s the ViewModel’s responsibility to do that, rather than the responsibility of the Controller, or the View.

    This keeps your concerns nice and segregated. Your Controller doesn’t care exactly what specific data your View needs (beyond the fact that it’s rendering some Details of a Product), or especially what format your View needs that data in. Your View doesn’t depend on the implementation details of your Model. Your Model doesn’t have to concern itself with how it’s being Viewed. If you have two Views rendering Products (e.g. Create, Edit, Summary, MoreDetails etc), those Views can have different ViewModels to expose only the data that each specific View needs, so your Views aren’t depending on eachother. Lovely 🙂

    Some further reading from various viewpoints:-

    http://www.thoughtclusters.com/2007/12/datamodel-and-viewmodel/

    http://stephenwalther.com/blog/archive/2009/04/13/asp.net-mvc-tip-50-ndash-create-view-models.aspx

    http://www.nikhilk.net/Silverlight-ViewModel-MVC.aspx

    I think ViewModels are a particularly .NET thing, but I see no reason at all why the pattern can’t be used in PHP.

    Hope this helps.

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

Sidebar

Related Questions

I have to make a view that shows unrelated data from multiple tables. I
The data model in my program has a number of discrete states, but I
With the 2.3.x+ rails feature of nested models, I think I need to have
I've never had the need to really ever use any of the .NET Data
What flaws do you see in the following design, (and what would be your
I'm an amateur, admittedly so, but I'm having fun trying to learn a little
Our application is well structured (well we did our best!) and we have split
I am working on a exe to export SQL to Access, we do not
My company hired a contractor to do a small project for us, for which

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.