public List <SelectListItem> GetForeignData(List <int> selectIdList) { List <SelectListItem> data = new List <SelectListItem>(); data = ArticleCateService.GetALL().ToList().Select(x => new SelectListItem { Text = x.CateName, Value = x.ID.ToString(), Selected = selectIdList.Contains(x.ID) }).ToList(); return(data); }
private List <SelectListItem> GetSelectList(int value = 0) { var list = Utilities.GetSelectListData( articleCateService.GetALL().ToList() , item => item.ID , item => item.CateName, true).ToList(); if (value != 0) { list.Single(x => x.Value == value.ToString()).Selected = true; } return(list); }
public ActionResult ArticleCode(int pid = 0) { var query = ArticleCateService.GetALL(); if (pid == 0) { query = query.Where(x => x.PID.Equals(null)); } else { query = query.Where(x => x.PID == pid); } var selectlist = Utilities.CreateSelectList( query.ToList() , item => item.ID , item => item.CateName, false); return(Json(selectlist, JsonRequestBehavior.AllowGet)); }