我通過docs
獲取數據列表,其中包含當前登錄的用戶有權訪問的每個部門和功能的列表。我需要在View頁面上爲DropDownList填充一個不同的Departments列表和一個DropDownList的不同的列表。我目前甚至不使用docs
來做到這一點,但一個不同的LINQ查詢來實現這一點。有沒有一種方法可以使用我傳遞的當前模型?在查看比使用ViewBag更好的方法
var docs = (Long LINQ query that joins in four different tables and returns a model)
ViewBag.DepartmentList = db.Department.Where(x => (x.name != null)).Select(s => new SelectListItem
{
Value = s.name,
Text = s.name
})
.Distinct(); // Fill the viewbag with a unique list of 'Department's from the table.
ViewBag.FunctionList = db.Function.Where(x => (x.name != null)).Select(s => new SelectListItem
{
Value = s.name,
Text = s.name
})
.Distinct(); // Fill the viewbag with a unique list of 'Function's from the table.
代碼:(強類型的模型)
@model IEnumerable<DB.Models.MasterList>
@Html.DropDownList("DepartmentList", "Select a Department")
@Html.DropDownList("FunctionList", "Select a Function")
我想我明白這個更好一點,謝謝! – 2013-05-13 21:27:19