title: .Net MVC - Accessing the Database from within a View more than just Bad Practice?
body: <p>I've seen a few developers instantiate models that access the database from within a view. Typically they do this when they want to access an html partial and they just create a new viewmodel right there in the view :</p>
  
  <pre><code>&lt;div class='blogListing'&gt;
      @Html.Partial("BlogListing", new BlogListingViewModel(10));
  &lt;/div&gt;
  </code></pre>
  
  <p>To me, best practice would be to instantiate all of your models inside your ViewModels, then pass them to your partials. In the example below, BlogHomeViewModel would create a new BlogListingViewModel(10) and set it as a public property for the View to consume :</p>
  
  <pre><code>@Model BlogHomeViewModel
  
  &lt;div class='blogListing'&gt;
      @Html.Partial("BlogListing", Model.BlogListing);
  &lt;/div&gt;
  </code></pre>
  
  <p>My question is, is this more than just a bad practice / maintenance issue? Are there also performance concerns for accessing a database from within a View? I would think a model would be able to fire off all of the database requests at about the same time, but within a View you're already starting to render html, and thus must open and close more connections,slowing down page load. Am I off-base here?</p>