Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC Razor
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)
Posted 10-Oct-12 2:44am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you are using Razor Views
Use optionlabel in View
@Html.DropDownListFor(model => model.FieldName, (SelectList)ViewBag.DepartMent, Model.FieldName)
or Create SelectList and mention your selectedValue in Action
SelectList Banks = new SelectList(new Department().Seed(), "DepartmentName", "DepartmentId", "SelectedValue");
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thank your suggestion. actually i did mistake. when i create helper class i give name dept but when i call this i call deptid instead of dept.so, i correct it and it works.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 480
1 Bhavik_Patel 190
2 Richard MacCutchan 155
3 PhilLenoir 155
4 Gihan Liyanage 155
0 Sergey Alexandrovich Kryukov 8,688
1 OriginalGriff 7,237
2 CPallini 2,598
3 Richard MacCutchan 2,080
4 Abhinav S 1,888


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100