title: MVC 2 - Cookies Not Saving
body: <p>I have a simple application where I am trying to save a value into my cookie but it is not saving. Below is the code and I do not know where the problem is.</p>
  
  <p>Code below is from the controller:</p>
  
  <pre><code>public ActionResult Index()
  {
      string cookieValue = "";
  
      if (Request.Cookies["my_cookie"] != null)
      {
          cookieValue = Request.Cookies["my_cookie"].Value;
      }
  
      if (! string.IsNullOrEmpty(cookieValue ))
      {
          ViewData["ck"] = cookieValue;
      }
      else { ViewData["ck"] = "no cookie value"; }
  
      return View();
  }
  
  [AcceptVerbs(HttpVerbs.Post)]
  public ActionResult SaveCookieData(FormCollection formValue)
  {
      HttpCookie myCookie = new HttpCookie("my_cookie", formValue["cookieTXT"].ToString());
  
      Response.Cookies.Add(myCookie);
  }
  </code></pre>
  
  <p>This code is from the view:</p>
  
  <pre><code>&lt;% using (Html.BeginForm("SaveCookieData", "Home", FormMethod.Post)) { %&gt;
  &lt;textarea id="cookieTXT" rows="2" cols="20" runat="server" /&gt;
  &lt;input id="submitBTN" type="submit" value="Done" runat="server" /&gt;
  &lt;% } %&gt;
  
  &lt;% if (ViewData["ck"] != null) { %&gt;
  &lt;p&gt;Hello Cookie: &lt;%= ViewData["ck"]%&gt;&lt;/p&gt; 
  &lt;% } %&gt;
  </code></pre>
  
  <p>From what it looks like is my form submitted data for cookieTXT is empty because the value for formValue["cookieTXT"] is blank. I can not figure it out why?</p>
  
  <p>Thanks for the help.</p>