2012年10月5日 星期五

DropDownListFor 顯示資料庫值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Controller
 public ActionResult Edit(int id)
 {
    ViewBag.SiteTypeList = SF.CreatDropDownList(7);
    return View(PAR.GetPARByID(id));
 }

View
 id = "ID" 會自動對應資料庫值
 @Html.DropDownListFor(m => m.SiteID, (SelectList)ViewBag.SiteTypeList, new { id = "ID" }) 

Model

        public PARColumn GetPARByID(int id)
        {
            using (AbobSysEntities db = new AbobSysEntities())
            {
                var query = db.ProductAbnormalRecord.Where(f => f.ID == id).First();
                return new PARColumn
                {
                    SiteID = Convert.ToString(query.SiteID),
                    WorkOrderNum = query.WorkOrderNum
                };
            }
        }

public class PARColumn
{
   public string SiteID { get; set; }
}

2012年10月4日 星期四

entity 顯示單一欄位



string result = "";

            using (xxx db = new xxx())
            {
                result = db.MasterCodeDetail
                           .Where(f => f.ID == siteID)
                           .Select(f => new { f.Name })
                           .FirstOrDefault().Name.ToString();
            }
 return result;

Visual Studio JS intellisense 失效解決方式

  試了好久,發現到工具>選項>IntelliCode js項目設定啟用,重新開啟VS就正常了! 後來發現是TypeScript3.2版有問題停用,使用4.3版的TypeScript即可