Asp.net 查询字符串生成器错误

Asp.net 查询字符串生成器错误,asp.net,linq,Asp.net,Linq,我只是尝试使用字典数据来构建查询字符串。我使用这个函数 public static string BuildQueryString(this IDictionary<string, string> source, bool withoutEmptyString) { return source != null ? String.Join("&", source.Keys .Where(key => !withoutEmptyStr

我只是尝试使用字典数据来构建查询字符串。我使用这个函数

public static string BuildQueryString(this IDictionary<string, string> source, bool withoutEmptyString)
    {
        return source != null ? String.Join("&", source.Keys
        .Where(key => !withoutEmptyString || source.Values.Any(value => !String.IsNullOrEmpty(value)))
        .SelectMany(key => source.Values
            .Where(value => !withoutEmptyString || !String.IsNullOrEmpty(value))
            .Select(value => String.Format("{0}={1}", HttpUtility.UrlEncode(key), value != null ? HttpUtility.UrlEncode(value) : string.Empty)))
        .ToArray())
        : string.Empty;
    }
我在代码中做错了什么


谢谢

简单点的怎么样:

var fromSource = source.Where(s => !string.IsNullOrEmpty(s.Value)).Select(s => s.Key + "=" +     s.Value);
        return string.Join("&", fromSource.ToArray());

简单一点,比如:

var fromSource = source.Where(s => !string.IsNullOrEmpty(s.Value)).Select(s => s.Key + "=" +     s.Value);
        return string.Join("&", fromSource.ToArray());
请检查我的where条款是否适用于您


请检查我的where子句是否适用于您。

您希望得到什么输出<代码>“一=1&二=2&…六=6”?嗨,马塞尔B:是的,这就是我需要的输出你想要什么输出<代码>“一=1&二=2&…六=6”?你好,Marcel B:是的,这就是我需要的输出我想这会得到更多的“&”符号作为字符串,仍然需要删除或替换。谢谢你说得对……聚合将在开始处放置一个
&
,这不是我的本意。我要改变它。我想这会得到更多的“&”符号作为字符串,仍然需要删除或替换。谢谢你说得对……聚合将在开始处放置一个
&
,这不是我的本意。我要改变这一点。
var fromSource = source.Where(s => !string.IsNullOrEmpty(s.Value)).Select(s => s.Key + "=" +     s.Value);
        return string.Join("&", fromSource.ToArray());
return source != null ? string.Join("&", 
                                    source.Where(keyValuePair => withoutEmptyString && !string.IsNullOrEmpty(keyValuePair.Value))
                                          .Select(keyValuePair => string.Format("{0}={1}", keyValuePair.Key, keyValuePair.Value)))     
                      : string.Empty;