title: Access session variable from MVC razor view gives variable type instead of value
body: <p>I am trying to access a session variable inside a MVC razor view, the session variable is of type  User which has a property UserID, the code is like the following:</p>
  
  <pre><code>&lt;h3&gt;@((User)Session["LoggedOnUser"]).UserID&lt;/h3&gt;
  </code></pre>
  
  <p>It only prints the fully qualified type of the property instead of its value. I also tried the following:</p>
  
  <pre><code>@{User loginUser = (User)Session["LoggedOnUser"];}
  &lt;h3&gt;@loginUser.UserID&lt;/h3&gt;
  </code></pre>
  
  <p>It works this time. Can anyone tell me what's the difference of these two and why the first one does not work?</p>
  
  <p>Thanks.</p>