Advertisement

Advertisement

Asp.net Mvc 5 DropDownList using Database with Entity Framework using strongly binding

Asp.net Mvc 5 DropDownList using Database with Entity Framework  using strongly binding

Controller.cs  

EmpireEntities ee = new EmpireEntities();

        public ActionResult create()

        {

            List<employee> emplist = ee.employees.ToList();

            ViewBag.Ename = new SelectList(emplist, "eid", "ename");

            return View();

        }

        [HttpPost]

        public ActionResult create(employee e)

        {

            try

            {

                ee.employees.Add(e);

                ee.SaveChanges();

                return RedirectToAction("Index");

            }

            catch (Exception)

            {

                return View();

            }

        }


creta.cshtml

 @Html.DropDownListFor(model => model.ename, ViewBag.Ename as SelectList, "-------Select List---------", new { @class = "form-control" })

               

Asp.net Mvc 5 DropDownList using Database with Entity Framework using strongly binding Asp.net Mvc 5 DropDownList using Database with Entity Framework  using strongly binding Reviewed by Rikesh on April 26, 2023 Rating: 5

No comments:

Powered by Blogger.