title: ASP.Net Mvc - Is it acceptable for the View to call functions which may cause data retrieval?
body: <p>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?</p>
  
  <p>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.</p>
  
  <p>A quick pseudo example.</p>
  
  <pre><code>public interface IProduct
  {
      /* Some Members */
  
      /* Some Methods */
      decimal GetDiscount();
  }
  
  public class Product : IProduct
  {
      public decimal GetDiscount(){ ... /* causes database access */ }
  }
  </code></pre>
  
  <p>If the View has access to the Product class (it gets passed an IProduct object), it can call GetDiscount() and cause database access. </p>
  
  <p>I am thinking of ways to prevent this. Currently I am only coming up with multiple interface inheritance for the <code>Product</code> class. Instead of implementing just IProduct it would now implement <code>IProduct</code> and <code>IProductView</code>. IProductView would list the members of the class, IProduct would contain the method calls which could cause database access.</p>
  
  <p>The 'View' will only know about the <code>IProductView</code> interface onto the class and be unable to call methods which cause data access. </p>
  
  <p>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.</p>
  
  <p>So, My questions:</p>
  
  <ul>
  <li>Are there any best practices regarding this issue? </li>
  <li>How do other people using MVC stop the View being naughty and doing more to objects than they should?</li>
  </ul>