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 3: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 OriginalGriff 280
1 Sebastiaan Meijerink 145
2 Sergey Alexandrovich Kryukov 108
3 Abhinav S 94
4 BillWoodruff 85
0 Sergey Alexandrovich Kryukov 6,558
1 OriginalGriff 6,268
2 Peter Leow 2,534
3 Abhinav S 2,344
4 Maciej Los 2,297


Advertise | Privacy | Mobile
Web03 | 2.8.150414.1 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2015
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