Click here to Skip to main content
Rate this: bad
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
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");
Rate this: bad
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, i correct it and it works.

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

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 BillWoodruff 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475

Advertise | Privacy | Mobile
Web02 | 2.8.1411023.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