Search code examples
c#formcollection

Understanding FormCollection.AllKeys.Contains


I'm looking at a code block and can't grok what's happening with the line - formValues.AllKeys.Contains("Email_" + i); it looks like an assignment should be taking place but...

public ActionResult EditAdditionalLocations(int ID, int? count, FormCollection formValues)
{
    ...

    for (int i = 0; i < _count; i++)
    {
        formValues.AllKeys.Contains("Email_" + i);
        if (locations.Emails.Count > i)
        {
            locations.Emails[i] = formValues["Email_" + i];
        }
        else
        {
            locations.Emails.Add(formValues["Email_" + i]);
        }
    }
}

Solution

  • My guess is that something like this was intended:

    if (formValues.AllKeys.Contains("Email_" + i)) {
        if (locations.Emails.Count > i)
        {
            locations.Emails[i] = formValues["Email_" + i];
        }
        else
        {
            locations.Emails.Add(formValues["Email_" + i]);
        }
    }