Ejemplo n.º 1
0
        public ActionResult AddNew()
        {
            var obj   = new DBComponent();
            var depts = obj.GetAllDepts().Select(e => new SelectListItem {
                Text = e.DeptName, Value = e.DeptId.ToString()
            }).ToList();

            //Get all Depts from the source and convert it to List<SelectListItem> to use it inside DropDownList....
            ViewBag.Depts = depts;//Add it to ViewBag object to display in the view...
            return(View(new EmpTable()));
        }
Ejemplo n.º 2
0
        //Called when the User clicks the More Link in the View....
        public ActionResult Edit(string id)
        {
            var obj      = new DBComponent();                                           //Create UR DBComponent object
            int empid    = int.Parse(id);                                               //Convert string id to int empid
            var selected = obj.GetAllEmployees().FirstOrDefault(e => e.EmpID == empid); //find the employee by id...
            var depts    = obj.GetAllDepts().Select(e => new SelectListItem {
                Text = e.DeptName, Value = e.DeptId.ToString()
            }).ToList();

            //Get all Depts from the source and convert it to List<SelectListItem> to use it inside DropDownList....
            ViewBag.Depts = depts;//Add it to ViewBag object to display in the view...
            if (selected == null)
            {
                Response.Write("No Employee found to edit");
            }
            return(View(selected));//Render the View with selected emp as injection...
        }