My DB consists of Regions, Divisions & States. My application (ASP.NET MVC) application uses entityframework to bind data to DropDown.
- Created Action to bind Regions by default.
- Created Action with RegionId as parameter to retrive Divisions
- [HttpGet]
- public JsonResult GetDivisionsByRegions(string regionID = "")
- {
- try
- {
- List
allDivisions = new List (); - int ID = 0;
- if (int.TryParse(regionID, out ID))
- {
- using (GeoEntities data = new GeoEntities())
- {
- allDivisions = data.Divisions.Where(div => div.RegionID == ID).OrderBy(div => div.DivisionID).ToList();
- }
- }
- if (Request.IsAjaxRequest())
- {
- return new JsonResult
- {
- Data = allDivisions,
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- }
- else
- {
- return new JsonResult
- {
- Data = "Invalid Data",
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- }
- }
- finally
- {
- }
- }
- jQuery AJAX call to GET data from & bind to Dropdown.
- Able to get data from entity.
- Error when bindig to Division drop down
Please help me out..
Asma KhalidPosted Apr 10, 2017, 6:37 AM
Try your GetDivisionsByRegions(...) method linke below i.e.