开发者

selected value for dropdownbox in asp.net mvc using selectlist

开发者 https://www.devze.com 2022-12-31 07:46 出处:网络
i have following selectlist for dropdownbox in aspnet mvc. This is the editEmployee Action controller, so while edit page is displayed i want to display a selectvalue in dropdownbox,since \"SelectLis

i have following selectlist for dropdownbox in aspnet mvc.

This is the editEmployee Action controller, so while edit page is displayed i want to display a selectvalue in dropdownbox,since "SelectList" takes 3 parameters one for value,one for text and other is for selected value, here i'm not getting what should i pass in 3rd parameter, coz its asking a开发者_Go百科n object for selected value.


ViewData["DepartmentList"] = new SelectList(DepartmentRepository.GetDepartmentsBySchoolIdInList(ViewData["schoolId"].ToString()),"DepartmentId","DepartmentTitle");

here is the view


=Html.DropDownList("DepartmentList")


var deptList = DepartmentRepository.GetDepartmentsBySchoolIdInList(ViewData["schoolId"].ToString());

ViewData["DepartmentList"] = new SelectList(DepartmentRepository.GetDepartmentsBySchoolIdInList(deptList,"DepartmentId",deptList.First());
0

精彩评论

暂无评论...
验证码 换一张
取 消