title: View Template Rendering Difference between <%= %> and <% %>
body: <p>The following is taken from page 56 of <a href="http://www.wrox.com/WileyCDA/Section/id-321793.html" rel="nofollow noreferrer">Professional ASP.NET MVC 1.0</a>.</p>
  
  <blockquote>
    <p>When we look at the Details.aspx template more closely, we’ll find that it contains static HTML as well as embedded rendering code. &lt;% %> code nuggets execute code when the view template renders, and &lt;%= %> code nuggets execute the code contained within them and then render the result to the output stream of the template.</p>
  </blockquote>
  
  <p>The statement intrinsically makes sense, but I was unable to clearly articulate to a team member exactly what it meant. A more detailed explanation of what exactly is occurring would be useful.</p>
  
  <p>An example of usage from later in the chapter:</p>
  
  <pre><code>&lt;% foreach (var dinner in Model) { %&gt;
      &lt;li&gt;
          &lt;%= Html.Encode(dinner.Title) %&gt;
          on
          &lt;%= Html.Encode(dinner.EventDate.ToShortDateString())%&gt;
          @
         &lt;%= Html.Encode(dinner.EventDate.ToShortTimeString())%&gt;
      &lt;/li&gt;
  &lt;% } %&gt;
  </code></pre>