Browse Source

补原始数据功能,明文

lcl 4 tháng trước cách đây
mục cha
commit
50babb8014
2 tập tin đã thay đổi với 11 bổ sung5 xóa
  1. 7 2
      Controllers/HomeController.cs
  2. 4 3
      Views/Home/SourceDataToDb.cshtml

+ 7 - 2
Controllers/HomeController.cs

@@ -101,9 +101,14 @@ namespace MySystem.Controllers
         public ActionResult SourceDataToDb()
         {
             WebCMSEntities db = new WebCMSEntities();
-            Dictionary<string, string> dic = db.KqProducts.Select(m => new { m.SpProductType, m.Name }).ToDictionary(m => m.SpProductType, m => m.Name);
+            var list = db.KqProducts.Select(m => new { m.SpProductType, m.Name }).ToList();
+            List<string> strlist = new List<string>();
+            foreach(var sub in list)
+            {
+                strlist.Add(sub.SpProductType + "|" + sub.Name);
+            }
             db.Dispose();
-            ViewBag.dic = dic;
+            ViewBag.dic = strlist;
             return View();
         }
 

+ 4 - 3
Views/Home/SourceDataToDb.cshtml

@@ -1,5 +1,5 @@
 @{
-    Dictionary<int, string> dic = ViewBag.dic as Dictionary<int, string>;
+    List<string> dic = ViewBag.dic as List<string>;
 }
 <!DOCTYPE html>
 <html lang="en">
@@ -12,9 +12,10 @@
 <body>
     <div>
         品牌:<select id="brand">
-            @foreach(int Id in dic.Keys)
+            @foreach(string sub in dic)
             {
-            <option value="@Id">@dic[Id]</option>
+                string[] data = sub.Split('|');
+                <option value="@data[0]">@data[1]</option>
             }
         </select>
     </div>