views:

281

answers:

2

Lets say I've got an online dating site, users can filter the user list based on various criteria, Height, Age, BodyType, Ethnic Origin....

I want to pass the criteria to the pager, via QueryString. Height and Age are easy as these are ranges, and I would use

MinHeight=3&MaxHeight=12&MinAge=21&MaxAge=30

However other Criteria like BodyType and Ethnic orgins are Lists of ForeignKey values e.g:

Ethnitity:2,3,5

What is the best way to pass these as a QueryString? Should I convert it to a Json string eg:

www.site.com?filterjson={\"minage\":0,\"maxage\":0,\"minheight\":0,\"maxheight\":0,\"bodytypelist\":[1,2,3],"ethnicitylist\":[2,3,4],\"eyecolorlist\":[],\"haircolorlist\":[],\"orientationlist\":[]}

Or is this not-valid/overkill/too complex?

Maybe something like this:

MinHeight=3&MaxHeight=12&bodytypes=1,2,3&

and parse the list values by splitting the ','?????

I don't know the ups and downs of all these ideas. So how would you pass a list of values in a querystring?

A: 

Both will work, though querystring is much easier to be 'hacked'. However if you have it well protected from malicious/unexpected values, I say it's fine.

Consuming data via querystring is relatively more straightforward than from JSON.

o.k.w
+2  A: 

Using comma-separated values is the most pragmatic approach in my opinion. You can use this code to split values:

if (!string.IsNullOrEmpty(Request.QueryString["bodytypes"]))
{
   string[] rgs = Request.QueryString["bodytypes"].Split(new char[] { ',' });
}
Pavel Chuchuva
I'm inclined to agree although commas turn into somethig like this www.site.com/search?bodytype=?=2%2C3%2C4 %2C representing a comma. Doesn't look nice, but I guess that doesn't matter. But I am a little concerned that comma is not a valid character in a querystring. Not sure if this is a problem or not.
reach4thelasers
You can replace comma with dash (bodytype=1-2-3).
Pavel Chuchuva