[RESOLVED]How to use dropdownlist in cshtml page.


I am using the below ink to create insert,edit,delete records


All UI controls given int the above  example  (link) is text.

but I want to use dropdownlist with employeename and Employeeid 

Employeeid should be saved in database

but display should be Employee name in dropdownlist

In the above URL  example there is no insert statement as such.

How to manually change the insert query.Please help me

Thanks and regards



Hello rchandran.nr,

Try This

In Your Controller

public ActionResult Create()
            ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "EmployeeName");
            return View();

In View 

 @Html.DropDownList("EmployeeId", (SelectList)ViewBag.EmployeeId, "Select Employee")

Hope This Helps

Leave a Reply