title: Passing data from Partial View to its parent View
body: <p>If I have a View and a Partial View, is there any way that I can pass data from the Partial View to the parent?</p>
  
  <p>So if I have <code>View.cshtml</code>:</p>
  
  <pre><code>&lt;div id="@someDataFromPartialSomehow"&gt;
      @Html.Partial("_PartialView")
  &lt;/div&gt;
  </code></pre>
  
  <p>And <code>_PartialView.cshtml</code>:</p>
  
  <pre><code>@{ someDataFromPartialSomehow = "some-data" }
  
  &lt;div&gt;
      Some content
  &lt;/div&gt;
  </code></pre>
  
  <p>How would I go about implementing something like this?</p>
  
  <p>I tried to use <code>ViewBag.SomeDataFromPartialSomehow</code>, but this just results in <code>null</code> in the Parent.</p>
  
  <hr>
  
  <p><strong>An attempt</strong></p>
  
  <p>To try get around the problem of data being generated before being called I tried this:</p>
  
  <p><code>View.cshtml</code>:</p>
  
  <pre><code>@{ var result = Html.Partial("_PartialView"); }
  
  &lt;div id="@ViewData["Stuff"]"&gt;
      @result
  &lt;div&gt;
  </code></pre>
  
  <p><code>_PartialView.cshtml</code>:</p>
  
  <pre><code>@{ ViewData["Stuff"] = "foo"; }
  
  &lt;div&gt;
      Content
  &lt;/div&gt;
  </code></pre>
  
  <p>But the call to <code>@ViewDate["Stuff"]</code> still renders nothing unfortunately.</p>