³õʼ»¯Í¼Æ¬Ô´ List<MoImgCode> listCode 5 { { 8 var list = new List<MoImgCode>(); ); 10 var info = new DirectoryInfo(path); 11 foreach (var item in info.GetFiles()) 12 { 13 list.Add(new MoImgCode 14 { 15 Index = item.Name, )[0], 17 ImgUrl = item.FullName 18 }); 19 } 20 return list; 21 } 22 }
»ñÈ¡Ëæ»úСͼƬÑéÖ¤Âë·½·¨£º
»ñȡСͼƬÑéÖ¤Âë List<MoImgCode> CreateImgCode(string indexType, int strLen = 8) 8 { 9 var choiceCodeList = new List<MoImgCode>(); { compareList = new List<MoImgCode>(); 14 var imgCodeLen = listCode.Count; maxChoiceNum = 5; 18 var minChoiceNum = 2; 19 var rdChoiceNum = rm.Next(minChoiceNum, maxChoiceNum); choiceList = listCode.Where(b => b.IndexType == indexType).Take(rdChoiceNum); 22 foreach (var item in choiceList) 23 { 24 compareList.Add(new MoImgCode 25 { 26 Index = item.Index, 27 ImgUrl = item.ImgUrl, 28 IndexType = item.IndexType, 29 IsChoice = true 30 }); 31 } lessNum = strLen - choiceList.Count(); (int i = 0; i < lessNum; i++) 37 { 38 var lessCode = listCode.Where(b => !compareList.Any(bb => bb.IndexType == b.IndexType)).ToList(); 39 var val = rm.Next(0, lessCode.Count); 40 var otherItem = lessCode.Skip(val).Take(1).SingleOrDefault(); 41 compareList.Add(new MoImgCode 42 { 43 Index = otherItem.Index, 44 ImgUrl = otherItem.ImgUrl, 45 IndexType = otherItem.IndexType, 46 IsChoice = false 47 }); 48 } (var item in compareList) 52 { 53 var lessCode = compareList.Where(b => !choiceCodeList.Any(bb => bb.Index == b.Index)).ToList(); comparIndex = rm.Next(0, lessCode.Count); 56 choiceCodeList.Add(lessCode[comparIndex]); 57 } 58 } 59 catch (Exception ex) 60 { 61 } 62 return choiceCodeList; 63 }
» MVCÈçºÎʹÓÃͼƬÑéÖ¤Âë
ÓÉÓÚÎÒÃÇÐèÒªÔÚÒ³ÃæÉÏÌáʾÓû§Ñ¡Ôñ“xxx”ÀàÐ͵ÄͼƬ£¬ËùÒÔÐèҪͨ¹ýºǫ́·µ»ØÑéÖ¤ÂëµÄͼƬºÍͼƬÀàÐÍÃû³ÆÈ磺
ÏÔȻһ¸öaction·½·¨²»ÄÜͬʱ·µ»ØͼƬÁ÷ºÍÎÄ×Ö£¬ËùÒÔÎÒÕâÀï·Ö¿ªÁ½¸ö·½·¨·Ö±ð·µ»Ø“Æó¶ì”ºÍͼƬ£¬·½·¨´úÂëÈ磺
¡¡