title: Razor Pages: Set cookie from _Layout.cshtml
body: <p>In _Layout.cshtml I have menu to change language of the application, like:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;nav id="nav-lang"&gt;
                      &lt;ul&gt;
                          &lt;li&gt;
  &lt;a href="?culture=en-EN"&gt;EN&lt;/a&gt;
                          &lt;/li&gt;
                          &lt;li&gt;
                              &lt;a href="?culture=pl-PL"&gt;PL&lt;/a&gt;
                          &lt;/li&gt;
                      &lt;/ul&gt;
                  
              &lt;/nav&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>What it does is reloading the page and sets new culture - works well. The thing is, that if the user changes culture and then go to other page within my app, default culture is loaded. I checked my options and the best choice seems to be setting a cookie "UserCulture" to e.g. "c=pl-PL|uic=pl-PL". The thing is I don't really know how to do it  from  in razor pages. I think that I should have a  with asp-page-handler set to some method (e.g. "SetCulture") and have setting cookie in that method, but this  causes some problems:</p>
  
  <ul>
  <li>where to put "SetCulture" if the form would be in _Layout.cshtml?
  _Layout.cshtml doesn't have code behind file</li>
  <li>how to submit the form from <em>anchor</em>? If I put <em>input type="submit"</em> it
  ruins the look of the menu completely.. I know I could do it from js
  but I try to avoid js where it's not absolutely required, especially
  for such basic stuff..</li>
  </ul>
  
  <p>I might be missing something very basic here, I'm quite new to Razor Pages still. From the hindsight I should have probably sticked to MVC but Razor Pages was said to be <em>easier</em>..</p>