0

I have a forms collection (fc) and I'm attempting to append to an email the values of the 'key' and the 'value'. I'm having no problem with the key (newKey), but I can't seem to code the 'value' properly. The 'for' loop checks to see if the key's first 3 characters of the key are 'ddl' indicating it came from a dropdownlist. if so, the loop should append the value from the dropdownlist control (the value of the key-value pair). (If not, the loop calls another method to append either a yes or no based upon the value of a checkbox control) Thanks in advance.

       //Append new key-value pairs implemented since legacy keys
        for (int i = 0; i < newKeys.Length; i++ )
        {

            //Checks for prefix of element to determine type of element
            if(newKeys[i].Substring(0,3) == "ddl"){
                sb.Append(newKeys[i] + ":  " + fc.GetValue(newKeys[i]) + "\",<br />");
                sb.Append(newKeys[i] + ":  " + fc.GetValues(newKeys[i].ToString())  + "\",<br />");
            }
            else{
            sb.Append(newKeys[i] + ",\"" + Boolean(fc[newKeys[i]]) + "\",<br />");
            }
        }

The 2 sb.append commands return the following:

ddlStratacacheConstellationManagerRole: System.Web.Mvc.ValueProviderResult" ddlStratacacheConstellationManagerRole: System.String[]",

tereško
  • 58,060
  • 25
  • 98
  • 150
Susan
  • 1,822
  • 8
  • 47
  • 69
  • what is happening instead? Could you provide us with an example output (or input)? – Zruty Nov 14 '11 at 15:59
  • The first sb.Append is returning the following value: System.Web.Mvc.ValueProviderResult". The seconding sb.Append is returning the following value: System.String[]" BY THE WAY, I have omitted the key values in the above results since they come out just fine! – Susan Nov 14 '11 at 16:09

1 Answers1

0

The values you are writing aren't of type String, nor they have the ToString() method overridden.

That's why the standard object.ToString() method is called and the object's type name is appended to the string.

To remedy this, you either need to override the ToString() method of all possible form collection's values, or think of some other algorithm, which would iterate over collections and output the corresponding values.

Zruty
  • 8,377
  • 1
  • 25
  • 31