title: an item with the same key has already been added mvc
body: <p>Hello I am trying to split the results from a string into a dictionary so I can add the numbers together.  This is information received from a texting api a client will text in an account + the amount they want to donate and multiple accounts are separated by commas ex th 20.00, bf 10.00 etc.</p>
  
  <p>When I run the code it worked find in windows form's but when i converted over to MVC I get the error "an item with the same key has already been added" which i know means its duplicating an key.  I tried entering an if statement during the foreach loop:</p>
  
  <pre><code>    if(!tester.containsKey(j){} 
  </code></pre>
  
  <p>but that did not always solve the problem and created a new error about out of range. Below is my current code:</p>
  
  <pre><code>    public ActionResult register(text2give reg)
      {
          string body = reg.body;
          try
          {
              var items = body.Split(',');
  
              Dictionary&lt;string, float&gt; tester = new Dictionary&lt;string, float&gt;();
              var j = 0;
              var total = 0f;
              while (j &lt; body.Length)
              {
  
                  foreach (var item in items)
                  {
  
                      var s = item.Trim().Split(' ');
                      tester.Add(s[0], float.Parse(s[1]));
                      total += float.Parse(s[1]);
                      j++;
  
                  }
              }
              ViewBag.total = total;
          }
          catch (Exception ex)
          {
              Response.Write(ex.ToString());
          }
          return View(reg);
      }
  </code></pre>