/// <summary> /// Model对象转换为uri网址参数形式 /// </summary> /// <param name="obj">Model对象</param> /// <param name="url">前部分网址</param> /// <returns></returns> public static string ModelToUriParam(this object obj, string url = "") { PropertyInfo[] propertis = obj.GetType().GetProperties(); StringBuilder sb = new StringBuilder(); sb.Append(url); sb.Append("?"); foreach (var p in propertis) { var v = p.GetValue(obj, null); if (v == null) continue; sb.Append(p.Name); sb.Append("="); sb.Append(HttpUtility.UrlEncode(v.ToString())); sb.Append("&"); } sb.Remove(sb.Length - 1, 1); return sb.ToString(); }