1

我有一个数据表,我在其中添加了分配工作链接....当单击它时,它会将我带到一个 assinedwork 按钮,我在下拉列表中绑定项目名称中的数据...和复选框...

Table for Projects
-----------

ProjetsId  |  ProjectName  |Decscription..
 1         |    aaaa       |    hihihihi
 2         |   bbbb         |  helohelo

 like that .....
 to bind the project name to Dropdownlist.

Table for Employee
-------------------
EmployeeId  |  EmployeNameName  |EmployeDescription..
 1         |    aaaa            |    hihihihi
 2         |   bbbb             |  helohelo

to bind the EmployeName to Checkbox
please help me .....................
4

1 回答 1

0

绑定到下拉列表

基本上,您必须创建一个可枚举的集合SelectListItem并通过ViewBagView Model将其传递给控制器​​。

从动作来看,

public ViewResult Edit(int id)
{
   ...

   var projects = _repository.GetAllProjects().Select(p => 
                     new SelectListItem
                     {
                        Text = p.ProjectName,
                        Value = p.ProjectsId.ToString()
                     });

   ViewBag.Projects = projects; // you can also use viewmodel

   ...
}

从外观上看,

@Html.DropDownListFor(x => x.ProjectId, ViewBag.Projects, "Choose a project")
于 2012-07-18T10:11:56.760 回答