这段代码应该怎么写?我在if (!query.Keys[i].Contains("ddl"))上得到对象引用未设置为对象的实例
string getLink(int toPage)
{
NameValueCollection query = HttpUtility.ParseQueryString(Request.Url.Query);
query["p"] = toPage.ToString();
string url = Request.Path;
int count = query.Count;
for (int i = 0; i < count; i++)
{
if (!query.Keys[i].Contains("ddl"))
url += string.Format("{0}{1}={2}",
i == 0 ? "?" : "&",
query.Keys[i],
query.Keys[i] == "category" ? string.Join("TTT", query.GetValues(i)).Replace(" ", "+") : string.Join(",", query.GetValues(i)));
}