title: @ViewBag getting null value from UserProfile
body: <p>i'm having some problems with to pass value from <code>UserProfile</code> to @Viewbag to show in <code>Index.cshtml</code>.</p>
  
  <p><strong>Let's explain</strong>:</p>
  
  <p>When i'm do a Register of new user or Login, i'm trying to pass <code>UserType</code> field from <code>UserProfile</code> in a viewbag.
  <em>UserType is a custom field that i create on <code>UserProfile</code> to validate if the user is a "Musico" or "Ouvinte"</em></p>
  
  <p>After debug application, I see that viewbag is taking NULL value.</p>
  
  <p>This is the code that i try to get value from <code>UserProfile</code> in <code>Register and Login post method</code>:</p>
  
  <p><strong>LOGIN POST METHOD</strong></p>
  
  <pre><code>[HttpPost] 
  [AllowAnonymous]
  [ValidateAntiForgeryToken]
  public ActionResult Login(LoginModel model, string returnUrl)
  {
      if (ModelState.IsValid &amp;&amp; WebSecurity.Login(model.UserName,
                                                  model.Password,
                                                  persistCookie: model.RememberMe))
      {
          var context = new UsersContext();
          var username = User.Identity.Name;
          var user = context.UserProfiles.SingleOrDefault(u =&gt; u.UserName == username);
          var userType = user.UserType;
  
          TempData["UserType"] = userType; //Taking UserType from User Profile
          return RedirectToLocal(returnUrl);
      }
  
      // If we got this far, something failed, redisplay form
      ModelState.AddModelError("", "The user name or password provided is incorrect.");
      return View(model); 
  }
  </code></pre>
  
  <p><strong>REGISTER POST METHOD</strong></p>
  
  <pre><code>[HttpPost]
  [AllowAnonymous]
  [ValidateAntiForgeryToken]
  public ActionResult Register(RegisterModel model)
  {
      if (ModelState.IsValid)
      {
          // Attempt to register the user
          try
          {
              var context = new UsersContext();
              var username = User.Identity.Name;
              var user = context.UserProfiles
                                .SingleOrDefault(u =&gt; u.UserName == username);
              var userType = user.UserType;
              WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new
              {
                  UserType = model.UserType
              });
              WebSecurity.Login(model.UserName, model.Password);
  
              // string currentUserType = u.UserType;                    
              TempData["UserType"] = userType;//Get the userType to validate on _Layout
              return RedirectToAction("Index", "Home");
          }
          catch (MembershipCreateUserException e)
          {
              ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
          }
      }
      return View(model);
  }
  </code></pre>
  
  <p><strong>Calling viewbag in part of Index page</strong></p>
  
  <pre><code>&lt;p&gt;
  @if (Request.IsAuthenticated &amp;&amp; ViewBag.UserType.Equals("Musico")) 
           {
                &lt;span&gt;musico&lt;/span&gt;
           }
           else if (Request.IsAuthenticated &amp;&amp; ViewBag.UserType.Equals("Ouvinte"))
           {
               &lt;span&gt;ouvinte&lt;/span&gt;
           } else{
            &lt;span&gt;teste&lt;/span&gt;
           }
  &lt;/p&gt;
  </code></pre>
  
  <p><strong>HomeController</strong></p>
  
  <pre><code>public ActionResult Index()
  {
      ViewBag.UserType = TempData["UserType"];
      return View();
  }
  </code></pre>