title: How do I pass data from a controller action to child action in the layout template?
body: <p>I have a search form that is displayed on every page in my application. It is generated using a child action:</p>
  
  <pre><code>[ChildActionOnly]
  public PartialViewResult Form(SearchFormViewModel model)
  {
      model.LanguageList = ReferenceService.GetLanguageList();
      model.SubjectList = ReferenceService.GetSubjectList();
  
      return PartialView("_SearchForm", model);
  }
  </code></pre>
  
  <p>and the following view model</p>
  
  <pre><code>public class SearchFormViewModel
  {
      public int Page { get; set; }
  
      public string Name { get; set; }
  
      public string Location { get; set; }
  
      public IList&lt;Subject&gt; SubjectList { get; internal set; }
  
      public IList&lt;Language&gt; LanguageList { get; internal set; }
  }
  </code></pre>
  
  <p>and called from my layout, which all my views inherit from.</p>
  
  <pre><code>@Html.Action("Form", "Search")
  </code></pre>
  
  <p>The form is submitted with a GET e.g. <code>/search/results?Subject=1&amp;Location=United+Kingdom</code>, so the form is populated on the results page, and the action for page performs the search and displays the results.</p>
  
  <pre><code>public ViewResult Results(SearchFormViewModel searchModel)
  {
  ...
  </code></pre>
  
  <p>I also have an action to handle some friendly urls for searching e.g. <code>/computing/united-kingdom</code> which uses a custom route to direct to correct action.</p>
  
  <pre><code>public ViewResult FriendlyResults(string subject, string location)
  </code></pre>
  
  <p>This action matches the url components to search parameters, performs a search and displays the results.</p>
  
  <p>What I want to do is populate the search form for friendly urls i.e. pass the search parameters to the <code>Form</code> child action, so that you can see what you have searched for.</p>
  
  <p>The only way I can think to do this is do store the 'friendly search' model in the <code>ViewBag</code>, and pass this as a parameter to the Form action, if it is populated. This doesn't feel right to me. </p>
  
  <p>Is there a better way or approach to do this?</p>