title: Modifying MVC 3 ViewBag in a partial view does not persist to the _Layout.cshtml
body: <p>I am using MVC 3 with the Razor view engine.  I want to set some values in the ViewBag inside a Partial View and want retrieve those values in my _Layout.cshtml.  For example, when you setup a default ASP.NET MVC 3 project you get a _Layout.cshtml file in the "/Views/Shared" folder.  In that _Layout.cshtml the Page Title is set like this: </p>
  
  <pre><code>&lt;title&gt;@ViewBag.PageTitle&lt;/title&gt;
  </code></pre>
  
  <p>Then in "/Views/Home/About.cshtml" view the contents of the ViewBag are modified:</p>
  
  <pre><code>@{
      ViewBag.Title = "About Us";
  }
  </code></pre>
  
  <p>This works fine. When the About view is rendered the page title is "About Us".  So, now I want to render a Partial view inside my About view and I want to modify the ViewBag.Title inside my Partial view. ("/Views/Shared/SomePartial.cshtml")</p>
  
  <pre><code>@Html.Partial("SomePartial")
  </code></pre>
  
  <p>In this Partial view I have this code:</p>
  
  <pre><code>@{
      ViewBag.Title = "About Us From The Partial View";
  }
  </code></pre>
  
  <p>When I debug this code I see the ViewBag.Title get set to "About Us" and then in the Partial view I see it get reset to "About Us From The Partial View", but when the code hits the _Layout.cshtml it goes back to "About Us".  </p>
  
  <p>Does this mean that if the contents of the ViewBag are modified in a Partial view, those changes will not appear(be accessible) in the main view (About.cshtml) or the _Layout.cshtml?</p>
  
  <p>Thanks in advance!</p>