title: set c# mvc session variable via hard-coded html select
body: <p>I have a C# MVC view that depends on the model data being passed through - tables of numbers - that requires the view to set a threshold that the view starts rendering the data, i.e.</p>
  
  <pre><code>@for (var value = ["threshold"]; value &lt;= 5; value++){
      ...
  }
  </code></pre>
  
  <p>My current thinking is that the best way to handle this is to have an html <code>select</code> that changes the session variable:</p>
  
  <pre><code>&lt;select id="thresholdSelect"&gt;
      &lt;option value="1"&gt;1&lt;/option&gt;
      &lt;option value="2"&gt;2&lt;/option&gt;
      &lt;option value="3"&gt;3&lt;/option&gt;
      &lt;option value="4"&gt;4&lt;/option&gt;
      &lt;option value="5"&gt;5&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Unfortunately, my knowledge of C# MVC means that I don't know how to set the session variable in this way, and my perusal of DropDownListFor boggles my mind.</p>
  
  <p>It seems overly complicated, given the requirement is for hard-coded values limited only to a single page, meaning I would expect the ideal answer to be a few lines in the view that trigger on a change event for a select element. Examples for the DropDownListFor in comparison shows it bouncing around the related controller and model and gets data stored from databases, which is overkill for what I need.</p>
  
  <p>How do I do this? I've been setting session variables at the controller level, but now need one at the view level.</p>
  
  <p>The basic steps I need to implement are:</p>
  
  <ol>
  <li>Show the page with a default session variable if not set (easily done in the controller before returning the view)</li>
  <li>Show a select element with the threshold values (easily done as I've put the code
  in the question)</li>
  <li>When the select element changes, fire an event that sets the session variable to the selected value.</li>
  </ol>