public ActionResult GetCity(int state) { Employee1Context context = new Employee1Context(); var cities = context.CityList.Where(c => c.StateId == state); return(Json(cities, JsonRequestBehavior.AllowGet)); }
/* #region--Create Method-- * public ActionResult Create() * { * * Employee1Context context = new Employee1Context(); * ViewBag.StateList = context.StateList; * var model = new Employee(); * return View(model); * } * * * [HttpPost] * public ActionResult Create(Employee model) * { * // Employee1Context context = new Employee1Context (); * * if (ModelState.IsValid) * { * context.EmpList.Add(model); * context.SaveChanges(); * return RedirectToAction("Index"); * * } * ViewBag.StateList = context.StateList; * return View(model); * } #endregion */ #region --GetData For DataTable-- public ActionResult GetData() { using (Employee1Context context = new Employee1Context()) { var EmployeeData = context.EmpList.OrderBy(a => a.EmployeeName).ToList(); return(Json(new { data = EmployeeData }, JsonRequestBehavior.AllowGet)); } }
public HomeController() { context = new Employee1Context(); }