namespace ProjectName.Models
{
public class AllDropdownlist
{
public ITA_M_AGREEMENT agreement { get; set; }
public ITA_M_CATEGORY category { get; set; }
public ITA_M_DEPARTMENT department { get; set; }
public ITA_M_GROUPTEAM groupteam { get; set; }
public ITA_M_LOCATION location { get; set; }
public ITA_M_STATUS status { get; set; }
public ITA_M_TEAM team { get; set; }
public ITA_M_TYPE type { get; set; }
public ITA_M_MANUFACTURER manufacturer { get; set; }
}
}
ส่วนอันนี้คือ Controller ที่ผมพยายามเรียกใช้ครับ
Code (C#)
namespace ProjectName.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
public ActionResult Menu()
{
return View();
}
public ActionResult Hardware()
{
return View();
}
public ActionResult Software()
{
ITAssetEntities db = new ITAssetEntities();
AllDropdownlist allDDL = new AllDropdownlist();
allDDL.agreement = getAgreement();
allDDL.manufacturer = getMenufacturer();
allDDL.category = getCategory();
allDDL.department = getDepartment();
allDDL.groupteam = getGroupteam();
allDDL.location = getLocation();
allDDL.status = getStatus();
allDDL.team = getTeam();
allDDL.type = getType();
return View(allDDL);
}
}
สุดท้ายคือ ในส่วนของ DropdownListFor
Code (C#)
@Html.DropDownListFor(model =>model.category.DESCRITION, ViewBag.CategoryList as SelectList, "--select--", new { @class = "form-control" })
@Html.DropDownListFor(model => model.type.DESCRITION, ViewBag.DepartmentList as SelectList, "--select--", new { @class = "form-control" })
Tag : ASP, Oracle, Web (ASP.NET), LINQ, Entity Framework (EF), MVC
// Controller
List<SelectListItem> Data = new List<SelectListItem>();
// LV1
foreach (var LV1 in select DATA FROM DATA)
{
Data.Add(new SelectListItem() { Text = Text , Value = Value });
}
ViewBag.Projects = Data;
// View
@html.dropdownlist("ID",(IEnumerable<selectelistitems>)ViewBag.Projects)