Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i can view anybody record and then can edit it if i click edit button below record, after clicking it takes you to another page whihc shows textboxes and dropdown, checkboxes to edit and all textboxes contains values for that EmpID but problem is that i want pre selected value in DROPDOWN LIST, like it should pick corresponding value for each user a preselected like my textboxes. I am using LINQ TO SQL, MVC 3, asp.net C#

Controller:
C#
var DepNames = (from n in DataContext.HrDepts select new { n.DeptID, n.DeptName }).Distinct();
               ViewData["DeptName"] = new SelectList(DepNames, "DeptID", "DeptName", EmployeeValues.FirstOrDefault().DeptName);


View:
C#
@using EmployeeAttendance_app.Models
@model IEnumerable<GetEmployeeEditDetails_SpResult>
          
@{
    var Item = Model.FirstOrDefault();
 }
@Html.DropDownList("DeptID", (SelectList)ViewData["DeptName"])



help please
Posted

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900