title: mvc - How to assign a value to a partial view property from withing its parent view
body: <p>I have a View A, View B, and a View _C.</p>
  
  <p>View _C is a partial view that is rendered inside of View A and B:</p>
  
  <p>View A:</p>
  
  <pre><code>&lt;div style="margin-top:20px;"&gt;
  
      &lt;div&gt;
          @Html.Partial("~/Views/_C.cshtml", null, new ViewDataDictionary { { "WithRedirect", "true" } });
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>View B</p>
  
  <pre><code>&lt;div style="margin-top:20px;"&gt;
  
      &lt;div&gt;
          @Html.Partial("~/Views/_C.cshtml", null, new ViewDataDictionary { { "WithRedirect", "false" } });
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>View C(partial view) - code fragment:</p>
  
  <pre><code>.
  .
  
  &lt;td style="padding-bottom: 8px;"&gt;
     @Html.EditorFor(model =&gt; model.CurrentPassword, new { htmlAttributes = new { @class = "form-control k-textbox checkError", placeholder = "Enter current password" } })
  &lt;/td&gt; 
  .
  .
  </code></pre>
  
  <p>When rendering partial view, I need to set a flag "WithRedirect" to refer to it later in the controller to decide if I need to redirect to another view or not:</p>
  
  <pre><code>string withRedirect = this.ViewData.ContainsKey("WithRedirect") ? this.ViewData["WithRedirect"].ToString() : string.Empty;
  </code></pre>
  
  <p>if(WithRedirect.Equals("true")
      return Redirect(returnUrl ?? Url.Action("Index", "Page1"));
  else
      return Redirect(returnUrl ?? Url.Action("Index", "Page2"));</p>
  
  <p>When debugging the controller, <code>WithRedirect</code> variable is an empty string.</p>
  
  <p>What am I doing wrong and what is the solution?</p>