Link to home
Start Free TrialLog in
Avatar of nvs_victor
nvs_victorFlag for United States of America

asked on

Getting a SELECT MULTIPLE element to pass its multiple values into an array, after a POST.

Hi experts,

I’m having trouble getting a SELECT MULTIPLE element to pass its multiple values into an array, after a POST.

Basically it’s this question:
http://www.sitepoint.com/forums/showthread.php?163734-Process-a-SELECT-MULTIPLE-POST

But how do I pass it into an array in ASP.NET C# syntax? Is it possible?

Currently, I have this code:

@{
        String [] countryID ;
        if (IsPost) {
                countryID = Request.Form["country[]"]; 
        }
}

<select multiple size="10" name="country[]" style="width: 200px;">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
</option>
</select>

Open in new window



 When I run the file, I get this error.

CS0029: Cannot implicitly convert type 'string' to 'string[]'

Open in new window


Apparently, the POST operation is passing the country element as a string. I need it to pass as an array, as the link talks about in PHP.

I assume I can’t do this with ASP.NET C#, am I correct? Do I need PHP to do this?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nvs_victor

ASKER

Hi  robert_schutt!

Thanks for your prompt help!

Strangely, today, it's working as expecting... producing a comma separated value.

Yesterday, without the array [] thing, it was only displaying the correct value if only one item was selected, but when multiple items were selected, it would display 0. Hence why I asked this question.

Strange. I don't recall anything I did differently from yesterday.

But it is good news :)

Thanks for your help!
I can't even reproduce what I saw yesterday with the zero thing... bizarre!
robert_schutt helped me assure me that it will pass comma separated.