title: How to increment value whenever same button is clicked?
body: <p>I would like int countHarry to keep incrementing by 1 whenever user clicks on "Vote Harry" button. The output will be written inside "data.txt". However, my data.txt will only show value as 1. Need advise. Thanks.</p>
  
  <p>This is a .cshtml file.</p>
  
  <p>Current output: Harry, 1
  Expected output: Harry, 3 (where int value increases upon click each time)</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-js lang-js prettyprint-override"><code>@{
      var result = "";
      int countJohn = 1;
      int countHarry = 1;
  
      if (IsPost)
      {
          var dataFile = Server.MapPath(@"~/App_Data/data.txt");
  
          if (Request["submit"] == "Vote Harry")
          {
  
              //var harry = Request["Harry"];
  
              var userData = "Harry" + "," + countHarry + Environment.NewLine;
  
              File.AppendAllText(@dataFile, userData);
  
              // countHarry += countHarry;  does not increases the count inside  .txt at all
  
              result = "Information saved.";
          }
  
          else if (Request["submit"] == "Vote John")
          {
  
              //var john = Request["John"];
  
              var userData = "John" + "," + (Int32.Parse("1")) + Environment.NewLine;
  
              File.AppendAllText(@dataFile, userData);
  
              result = "Information saved.";
  
              countJohn += 1;
          }
      }
   }
      </code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Elections&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" method="post"&gt;
          &lt;div&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Harry&lt;/td&gt;
                      &lt;td&gt;&lt;input id="Harry" name="submit" type="submit" value="Vote Harry"/&gt;&lt;/td&gt;
  
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;John&lt;/td&gt;
                      &lt;td&gt;&lt;input id="John" name="submit" type="submit" value="Vote John" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Bryan&lt;/td&gt;
                      &lt;td&gt;&lt;input id="Bryan" name="submit" type="submit" value="Vote Bryan" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Jack&lt;/td&gt;
                      &lt;td&gt;&lt;input id="Jack" name="submit" type="submit" value="Vote Jack" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/div&gt;
          &lt;div&gt;
              @if (result != "")
              {
                  &lt;p&gt;Result: @result&lt;/p&gt;
              }
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>