Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI,

I am trying to study MVC. I have a list page where there is a checkbox, when i click it i made an ajax method to fetch data from SQL. The returned data is of DataTable format . How can i read contents from that and display the result.

This is the code i have done. This is the controller

C#
[HttpPost]
       public JsonResult Index(bool includeInActive = false, string searchKey = "", string sortField = "ID", string sortDirection = "asc")
       {
           objEmployee = new Employee();
           try
           {
               objEmployee.GetEmployees(sortField, sortDirection, searchKey, includeInActive);
               return Json(objEmployee.dtEmployees, JsonRequestBehavior.AllowGet);
           }
           catch (Exception ex)
           {
               throw ex;
           }
       }


Pls help me.
Posted
Comments
Pheonyx 28-Mar-14 11:18am    
From looking at that requirement, personally I wouldn't use a "HttpPost" instead I would use a "HttpGet" as you are retrieving data not saving stuff.

I would get the collection as a datatable or an enumberale list and return a "PartialView" which has been built based on it. Then in the Ajax success function load the partial view into a div on the page for the user to see.
Arjun Menon U.K 28-Mar-14 11:31am    
what if i am not using partial view. I used post coz i already have a index action
Pheonyx 28-Mar-14 12:02pm    
You are not limited to one "get" action, and a page can call multiple actions.
Post's are primarily for submitting data.
Arjun Menon U.K 31-Mar-14 4:01am    
Ok, but i didn't get the answer yet :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900