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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:16:57+00:00 2026-05-11T01:16:57+00:00

I am currently playing around with the Asp.Net mvc framework and loving it compared

  • 0

I am currently playing around with the Asp.Net mvc framework and loving it compared to the classic asp.net way. One thing I am mooting is whether or not it is acceptable for a View to cause (indirectly) access to the database?

For example, I am using the controller to populate a custom data class with all the information I think the View needs to go about doing its job, however as I am passing objects to the view it also can cause database reads.

A quick pseudo example.

public interface IProduct {     /* Some Members */      /* Some Methods */     decimal GetDiscount(); }  public class Product : IProduct {     public decimal GetDiscount(){ ... /* causes database access */ } } 

If the View has access to the Product class (it gets passed an IProduct object), it can call GetDiscount() and cause database access.

I am thinking of ways to prevent this. Currently I am only coming up with multiple interface inheritance for the Product class. Instead of implementing just IProduct it would now implement IProduct and IProductView. IProductView would list the members of the class, IProduct would contain the method calls which could cause database access.

The ‘View’ will only know about the IProductView interface onto the class and be unable to call methods which cause data access.

I have other vague thoughts about ‘locking’ an object before it is passed to the view, but I can foresee huge scope for side effects with such a method.

So, My questions:

  • Are there any best practices regarding this issue?
  • How do other people using MVC stop the View being naughty and doing more to objects than they should?
  • 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. 2026-05-11T01:16:57+00:00Added an answer on May 11, 2026 at 1:16 am

    Your view isn’t really causing data access. The view is simply calling the GetDiscount() method in a model interface. It’s the model which is causing data access. Indeed, you could create another implementation of IProduct which wouldn’t cause data access, yet there would be no change to the view.

    Model objects that do lazy loading invariably cause data access when the view tries to extract data for display.

    Whether it’s OK is down to personal taste and preference.

    However, unless you’ve got a good reason for lazy loading, I’d prefer to load the data into the model object and then pass that ‘ready-baked’ for the view to display.

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

Sidebar

Ask A Question

Stats

  • Questions 71k
  • Answers 71k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer See the Java documentation for the Applet and Object tags.… May 11, 2026 at 1:28 pm
  • added an answer Traditional UNIX development (my nice little black box of joy)… May 11, 2026 at 1:28 pm
  • added an answer I resolved it using the XFA xml file and dotNet… May 11, 2026 at 1:28 pm

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.