title: Session variable in ASP.NET MVC
body: <p>I need to create something like a session variable in .net MVC.
  I'm using ViewData. First I set it in my Controller Index:</p>
  
  <pre><code>public ActionResult Index(int id)
      {
          ViewData["myID"] = id;
      }
  </code></pre>
  
  <p>Then, I'll need to use it in another function of the same controller. However, I have to send it to my view. Store the data into a . Then read it again.
  View:</p>
  
  <pre><code>&lt;input type="hidden" id="myID" name="myID" value='@ViewData["myID"]'  /&gt;
  </code></pre>
  
  <p>Other function of the controller where I get the id:</p>
  
  <pre><code>[HttpPost, ValidateInput(false)]
      public ActionResult Test(FormCollection form)
      {
          var pId = form["myID"];
      }
  </code></pre>
  
  <p>It works, but looks wrong (I'm new in .net mvc). Is there a way where I can set this id one time in my controller and then read/get it when I need?</p>
  
  <p>Thanks</p>