If I write query to fetch City column values:
- public JsonResult getEmpCity()
- {
- using (CompanyDBEntities dc = new CompanyDBEntities())
- {
- var query = (from p in dc.Emp_Information
- select p.City).ToList();
- return new JsonResult
- {
- Data = query.ToList(),
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- }
- }
Debug this call and see result.
Now write your code like below:
- public JsonResult getEmpCity()
- {
- using (CompanyDBEntities dc = new CompanyDBEntities())
- {
- var query = (from p in dc.Emp_Information
- select p.City).Distinct().ToList();
- return new JsonResult
- {
- Data = query.ToList(),
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- }
- }
And See result.