title: Why isn't my ViewBag setting available in my view?
body: <p>I have the following code in my HomeController's Index action, and the code below it in my layout. When I call up the Home/Index view, the UserName property isn't set, but I know it is set in my controller, as I examine the value with a breakpoint.</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>public ActionResult Index()
  {
      ViewData.Add("UserName", User.Identity.Name);
      return View();
  }
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <pre><code>@{ 
      if (User.Identity.IsAuthenticated)
      {
      &lt;text&gt;Hello &lt;/text&gt;
      @ViewBag.UserName &lt;text&gt; - &lt;/text&gt;
      @Html.ActionLink("Sign Out", "LogOff", "Account", null, new { style = "font-weight: bold;" })
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> When I try the following view code, as suggested in answers below, I get a the compilation error: <em>'System.Web.Mvc.HtmlHelper' has no applicable method named 'Display' but appears to have an extension method by that name.</em></p>
  
  <p>I wonder if this is not some side effect of my nested layouts? The layout for the view cited is _ThreeColumn, and the layout for the latter is _Layout, set as default in _ViewStart.</p>