Skip to content
Loading
+1
  • 0
    Hi
     
      I have below controller . How it will work
     
    public ActionResult Index()
    {
    return View();
    var data = dbLocation.GetAllLocation().ToList();
    return View(data);
    }
    public JsonResult List()
    {
    List listLocation = new List();
    var res = dbLocation.GetAllLocation().ToList();
    foreach (var item in res)
    {
    Location obj = new Location();
    obj.Id = item.Id;
    obj.Description = item.Description;
    obj.IsActive = item.IsActive;
    listLocation.Add(obj);
    }
    return Json(listLocation, JsonRequestBehavior.AllowGet);
    }
     
     
    Thanks 
    0
  • Sachin Singh
    0
    do like this
    1. public ActionResult Index()  
    2. {  
    3.   
    4. return View(new Location());  
    5. }  
    6. public JsonResult List()  
    7. {  
    8. List listLocation = new List();  
    9. var res = dbLocation.GetAllLocation().ToList();  
    10. foreach (var item in res)  
    11. {  
    12. Location obj = new Location();  
    13. obj.Id = item.Id;  
    14. obj.Description = item.Description;  
    15. obj.IsActive = item.IsActive;  
    16. listLocation.Add(obj);  
    17. }  
    18. return Json(listLocation, JsonRequestBehavior.AllowGet);  
    19. }  
    for dataTable you already have List(), so you don't need to pass list in your first method . 
    0