码迷,mamicode.com
首页 > 数据库 > 详细

c# 从数据库作为下拉列 删除重复的列 foreach()

时间:2016-08-22 10:46:24      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

 1   public ActionResult Index(YearCheckInfoRequest request)
 2         {
 3             //int a = -1;
 4             // if (request.DisasterScale == a.ToString()) { request.DisasterScale = null; };
 5             // if (request.MineName == a.ToString()) { request.MineName = null; };
 6             var result = this.YearCheckService.GetYearCheckList(request);
 7 
 8             YearCheckInfoRequest NewRequest = new YearCheckInfoRequest();
 9             Dictionary<int, String> dictionary = new Dictionary<int, string>();
10             var MineNameList = this.YearCheckService.GetYearCheckList(NewRequest);
11            
12             int i = 0;
13             List<String> mineNameList= new List<String>();
14             
15             foreach (YearCheckInfo yearCheck in MineNameList)
16             {
17                 if (!mineNameList.Contains(yearCheck.MineName))
18                 {
19                     mineNameList.Add(yearCheck.MineName);
20                     dictionary.Add(i, yearCheck.MineName);
21                     i++;
22                 }
23             }
24             this.ViewBag.MineName = new SelectList(dictionary, "", "value ");
25 
26             //默认查询日期
27             ViewBag.CheckTimeStart = request.CheckTimeStart.ToString("yyyy-MM-dd");
28             ViewBag.CheckTimeEnd = request.CheckTimeEnd.ToString("yyyy-MM-dd");
29 
30             return View(result);
31         }
1   <label>
2                     <span>矿山名称:</span>
3                     @Html.DropDownList("MineName", ViewBag.MineName as SelectList, "所有记录",new { @class = "m-wrap medium" })
4                   
5                 </label>

 

c# 从数据库作为下拉列 删除重复的列 foreach()

标签:

原文地址:http://www.cnblogs.com/ceccf/p/5794582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!