15

I am trying to send querystring parameter as below but i think that using comma in querystring is not valid so what is better alternative to comma separator for path parameter?

<a href="/?path=1,2,3"></a>

I don't want to send like <a href="/?path=1&path=2&path=3"></a> which can be quite long.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Freshblood
  • 6,285
  • 10
  • 59
  • 96

6 Answers6

14

You can use %2C, wich is the url-encoded value of ,.

rabusmar
  • 4,084
  • 1
  • 25
  • 29
  • Allready ASP.NET MVC Framework translate to url encoded value but i feel that it is not seo friendly or not better way. That is why i didnt want to use. Is there any downside of url encoded values ? – Freshblood Dec 02 '11 at 16:32
  • The HTTP protocols takes care of decoding the urls, so in your program the param `p` would be `1,2,3`, however, the user would see the url encoded in their browser, which you might now want, so I guess you could use `-` as the delimiter, since it doesn't need to bee encoded. – rabusmar Dec 02 '11 at 16:43
  • 1
    I don't see why it wouldn't be SEO friendly. It's in the query string anyway. – Antoine Aug 01 '14 at 08:56
9

The comma is allowed, also in its un-encoded form, as it is a reserved character.

Have a look at this RFC section: RFC 3986 - 2.2. Reserved Characters

As I understad this, it just depends on how your server handles URLs that contain a comma. Give it a try and find out.

Community
  • 1
  • 1
Adrian H.
  • 569
  • 6
  • 17
3

You could use the escaped (or percent-encoded if we're being pedantic) value of ',', or an unreserved character as per RFC 3986 (- _ . ~).

Community
  • 1
  • 1
Bell
  • 17,907
  • 4
  • 23
  • 25
0

You can send it simply, i use lodash to collect select product id

 vm.saleStartDate = vm.saleDateRange.startDate.toISOString();
 vm.saleEndDate = vm.saleDateRange.endDate.toISOString();

 vm.productIds = _.map(vm.selectedProducts, 'id').join(',');

 vm.iFrameURL = host + '/Reports/MonthWiseAvgSalesViewer.aspx?id=MonthWiseAvgSalesReport.rdlc&salesSD=' + vm.saleStartDate + '&salesED=' + vm.saleEndDate +
               '&prIds=' + vm.productIds
Maksud Alam
  • 169
  • 1
  • 3
0

If you are sending integers, use spaces as a separator.

Mathieu Dhondt
  • 8,405
  • 5
  • 37
  • 58
-3

You could use pipes "|" as a delimiter, but you're going to have to process it on the server side. Not sure it's worth the hassle though.

ek_ny
  • 10,153
  • 6
  • 47
  • 60