// // GET: /Account/UserNameAuto/ 自动提示 public ActionResult UserNameAuto(string query) { string[] emails = new string[] { "10000", "126.com", "163.com", "yeah.net", "sina.com", "sina.cn", "qq.com", "vip.qq.com", "sohu.com", "live.com", "msn.cn", "gmail.com" }; List <KeyValue> results = new List <KeyValue>(); if (String.IsNullOrEmpty(query)) { results.Add(new KeyValue() { value = "暂无结果", data = "0" }); return(Json(results, JsonRequestBehavior.AllowGet)); } for (int i = 0; i < emails.Length; i++) { var email = emails[i]; KeyValue item = new KeyValue(); if (query.Contains("@")) //有@才提示 { string query2 = query.Split('@')[1]; if (email.StartsWith(query2)) { item.value = query.Split('@')[0] + "@" + email.Trim(); item.data = i.ToString(); } results.Add(item); } // else // { // item.value = query + "@" + email.Trim(); // item.data = i.ToString(); // } } results = Utils.RemoveEmptyList(results); AutoStruct autoStruct = new AutoStruct(); autoStruct.query = "Unit"; autoStruct.suggestions = results; return(Json(autoStruct, JsonRequestBehavior.AllowGet)); }
// // GET: /Account/UserNameAuto/ 自动提示 public ActionResult UserNameAuto(string query) { string[] emails = new string[] { "10000", "126.com", "163.com", "yeah.net", "sina.com", "sina.cn", "qq.com", "vip.qq.com", "sohu.com", "live.com", "msn.cn", "gmail.com" }; List<KeyValue> results = new List<KeyValue>(); if (String.IsNullOrEmpty(query)) { results.Add(new KeyValue() {value = "暂无结果", data = "0"}); return Json(results, JsonRequestBehavior.AllowGet); } for (int i = 0; i < emails.Length; i++) { var email = emails[i]; KeyValue item = new KeyValue(); if (query.Contains("@")) //有@才提示 { string query2 = query.Split('@')[1]; if (email.StartsWith(query2)) { item.value = query.Split('@')[0] + "@" + email.Trim(); item.data = i.ToString(); } results.Add(item); } // else // { // item.value = query + "@" + email.Trim(); // item.data = i.ToString(); // } } results = Utils.RemoveEmptyList(results); AutoStruct autoStruct = new AutoStruct(); autoStruct.query = "Unit"; autoStruct.suggestions = results; return Json(autoStruct, JsonRequestBehavior.AllowGet); }