title: Save model in session and use it in view
body: <p>I've been looking at some of the answers on this site about saving model data to session but none seem to work for me, or most likely I am not understanding it correctly and not sure how to implement it.</p>
  
  <p>This is the latest solution I've been trying.
  <a href="https://stackoverflow.com/questions/26704800/how-to-save-object-to-session-in-asp-net">c# - How to save object to session in ASP.NET</a></p>
  
  <p>In the Index I get an error on declaring the model telling me User doesn't exist</p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class User
  {
      public int Id { get; set; }
      public string Username { get; set; }
      public string Password { get; set; }
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public ActionResult Index()
  {
      using (DefaultConnection db = new DefaultConnection())
      {
          var model = from u in db.Users select u;
  
          var vm = (User)Session["User"];
  
          return View(vm);
      }
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>@model User
  
  @Model.Username
  </code></pre>