Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I was not 100% sure about this. I tried using a set of repeated variables in the query string and c# handles it fine in the controller. For example:

?x=5&x=7&x=3

You send the values to a string[] and it is perfectly fine. I posted a question somewhere else (before trying this) and someone seems to be of the impression that repeating the same variable name in the query string is invalid or illegal (if I am understanding them correctly). He said that based on his difficulty with PHP not handling it very well (probably to do with you not being able to declare variables in PHP).

Could someone clarify that it is legal code (the repeated variable name in the query string)?

Additional: I know this may seem like a strange question to ask. If it is working then why bother questioning it? I just want to check to make sure that it is not something that will get deprecated down the road some time and cause problems. I cannot find any suggestion that it is legal to repeat variable names - I see people doing it but I cannot clarify the correctness of it.
Posted
Updated 22-Dec-15 8:21am
v2

1 solution

It appears to not have a well defined behavior

Take a look at this link:
http://stackoverflow.com/questions/1746507/authoritative-position-of-duplicate-http-get-query-keys[^]
 
Share this answer
 
Comments
Cheesus Toaster 23-Dec-15 9:36am    
Yes Steve, I am beginning to find this out now. From what I have gathered, you basically do whatever works best for the server side language. C# works fine if you define a string[] varName in the controller and then use name='varName' in the view for how ever many values you need. You have to do it differently in PHP apparently.

The thing is, I usually use the MVC 5 inbuilt select list helper. I could not do it this time so I found that using names to build an array or list worked best.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900