title: MVC Controller Action called from PartialView in _Layout.cshtml
body: <p>In my _Layout.cshtml I want to include a dropdown list in the site header. I'm not positive of the best way to do this, but I've tried to code it using a PartialView. It seems to be working, but when the form is submitted the page loads with only the dropdownlist.</p>
  
  <p><strong>ViewModel:</strong></p>
  
  <pre><code>namespace XXXX_Web_App.Models
  {
      public class LanguageListPartial
      {
          [DataType(DataType.Text)]
          [Display(Name = "Language")]
          public string Language { get; set; }
      }
  }
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>[AllowAnonymous]
  [ChildActionOnly]
  public ActionResult LanguageList()
  {
      ViewBag.LanguageList = GetLanguageList();
  
      return PartialView("_LanguageListPartial");
  }
  
  [AllowAnonymous]
  [HttpPost]
  public async Task&lt;ActionResult&gt; LanguageList(string language)
  {
      // Save selection to cookie
      HttpCookie cookie = new HttpCookie("UserSettings");
      cookie["Language"] = language;
      cookie.Expires = DateTime.Now.AddDays(-1);
      Response.Cookies.Add(cookie);
  
      // Save selection to user profile
      if (User.Identity.IsAuthenticated)
      {
          String userId = User.Identity.GetUserId();
          ApplicationUser user = await UserManager.FindByIdAsync(userId);
          user.Language = language;
          await UserManager.UpdateAsync(user);
      }
  
      ViewBag.LanguageList = GetLanguageList();
  
      return PartialView("_LanguageListPartial");
  }
  
  public List&lt;SelectListItem&gt; GetLanguageList()
  {
      List&lt;SelectListItem&gt; languages = new List&lt;SelectListItem&gt;();
      languages.Add(new SelectListItem { Text = "English", Value = "en-US" });
      languages.Add(new SelectListItem { Text = "Fran&amp;#231;ais", Value = "fr-CA" });
      languages.Add(new SelectListItem { Text = "Portugu&amp;#234;s", Value = "pt-BR" });
      languages.Add(new SelectListItem { Text = "Espa&amp;#241;ol", Value = "es-MX" });
      return languages;
  }
  </code></pre>
  
  <p><strong>Partial View:</strong></p>
  
  <pre><code>@model XXXX_Web_App.Models.LanguageListPartial
  
  @Html.DropDownListFor(
      x =&gt; x.Language,
      new SelectList(ViewBag.LanguageList, "Value", "Text"), 
      new { @class = "form-control toggle", onchange = "this.form.submit();"
  })
  </code></pre>
  
  <p><strong>_Layout.cshtml:</strong></p>
  
  <pre><code>@using Westwind.Globalization;
  @using Westwind.Globalization.Resources;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;title&gt;@ViewBag.Title&lt;/title&gt;
  
      @Styles.Render("~/Content/css")
      @Scripts.Render("~/bundles/modernizr") 
      @Scripts.Render("~/bundles/jquery")
      @Scripts.Render("~/bundles/jqueryUI")
      @Scripts.Render("~/bundles/bootstrap")
      @RenderSection("scripts", required: false)
  
  
    &lt;script src="/Scripts/jquery.cookie.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div style=""&gt;
  
      &lt;div class="header container"&gt;
  
           ... nav menu ...
  
      &lt;/div&gt;
  
      &lt;form action="/Account/LanguageList" method="post" &gt;
          @{Html.RenderAction("LanguageList", "Account");}
      &lt;/form&gt;
  
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-12"&gt;
                  @RenderBody()
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;footer class="container"&gt;
          &lt;hr /&gt;
          &lt;p&gt;&amp;copy; @DateTime.Now.Year&lt;/p&gt;
      &lt;/footer&gt;
  
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The desired logic is:</p>
  
  <p><strong>Every site/page visit</strong></p>
  
  <ul>
  <li>Anonymous user - load selection from cookie. Default to English. (not done yet)</li>
  <li>Authenticated user - load selection from user profile (not done yet)</li>
  </ul>
  
  <p><strong>On selection</strong></p>
  
  <ul>
  <li>Anonymous user - save selection to cookie</li>
  <li>Authenticated user - save selection to cookie and update user profile</li>
  </ul>
  
  <p>Like I said, this seems to be working except that when a selection is made the Controller action gets called and when the page reloads the only thing on the page is the dropdown list.</p>
  
  <p>How do I return the View in this situation?</p>
  
  <p>One other question, I would like the text in the dropdown list items to include the culture specific decorations, but they are displaying literally like <code>Fran&amp;#231;ais</code> instead. I don't see how I can use <code>Html.Encode()</code> in this situation. It's probably being caused by the way I am adding the items in <code>GetLanguageList()</code>. How do I avoid this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>To clarify, my excerpt from _Layout.cshtml above is just that - an excerpt. My _Layout.cshtml contains what you might expect of it - a header with logo and subtitle, navigation menu, and RenderBody() code. The page displays properly on the Partial View's GET Controller Action, but when I make a selection from the dropdown list the POST Controller Action only the dropdown list is displayed on the page - nothing else. _Layout.cshtml is gone and so are the contents of whatever page I am on.</p>