[ASP.NET MVC]編輯模式的下拉式選單

| Comments

因為剛玩ASP.NET MVC,對於真的很不熟,光搞了下拉式選單@Html.DropDownList我就快被搞死了,而且我又是用LINQ to Entities ,想要把編號放入Value為了要把他轉成數值就出現了問題,找了很久終於被我找到方法可以處理這個雷了><。簡單到有點…

image

Controllers

   1: public ActionResult match_Create()

   2: {

   3:     ViewBag.type_id = new SelectList(_db.type, "type_id", "type_name"); 

   4:     

   5:     return View();

   6: }

Views

   1: <div class="editor-field">

   2:     @Html.DropDownList("type_id","---請選擇--") 

   3:     @Html.ValidationMessageFor(model => model.type_id)

   4: </div>