问题描述
我有emp表和empno,名称,deptno(部门表中的fk)列.当我插入新员工时,我会在下拉列表中输入名称和部门编号.我可以在下拉列表中显示部门名称,并且可以在emp表中存储部门编号.但是我的问题是,当我尝试编辑特定员工时,我无法在下拉列表中绑定该特定部门编号,名称. />
在[httpget]
我得到了ID,名称(没有问题),我的下拉部门列表应该是返回的,部门名称没有保存,然后如果我想要的话,我可以更改部门(现在我加载该列表,但它选择了第一个值,如果我不这样做) '不更改部门,然后更新部门第一个值,因为它已经被选择)
Hi, i have emp table and empno,name,deptno(fk from department table)column.when i insert new employee i give name and department no in drop down list. i can display department name in dropdown list and i can store department no in emp table.but my problem is when i try to edit the particular employee then i can''t bind that particular department no,name in drop down list.
in [httpget]
i get id, name (no problem)and my drop down department list should be return save department no,name and then if i want then i can change department(now i load that list but it selected the first value and if i don''t change department then it update department first value as it is already selected)
推荐答案
@Html.DropDownListFor(model => model.FieldName, (SelectList)ViewBag.DepartMent, Model.FieldName)
或创建SelectList并在操作中提及您的selectedValue
or Create SelectList and mention your selectedValue in Action
SelectList Banks = new SelectList(new Department().Seed(), "DepartmentName", "DepartmentId", "SelectedValue");
这篇关于如何从选定的存储值返回mvc3的下拉列表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!