[RESOLVED]How to use dropdownlist in cshtml page.

Hi

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

http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4.

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

Chandran

 

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