1

Hi,

We are using MVC/JQuery for one web application: In one the screen users can generate charts. Now requirement as below:

1) Select Chart Criteria. (Client/Date Range/Chart Axis etc)

2) Press “Generate” Button… Which further makes a call to JQuery and then get the Data from Server through Ajax Call.

3)

public JsonResult GetDayData([DataSourceRequest]DataSourceRequest request,
      string clientID, DateTime? startDate, DateTime? endDate, string SortOrder))
{
    //Makes a call to Stored Procedure
    Stored procedure runs and return multiple datatables (ds.tavles[0], ds.tables[1] etc.
}

4) Based on these datatables we need to refresh/create 4-5 charts (assuming 4-5 datatables will be returned from stored procedure)

5) I am able to return dataTable[0] and create chart but I am not able to find how to return multiple Json objects in one call and how to handle those in JQuery/Ajax.

One approach is to make separate for each chart controller and return Json objects but I don’t want to make multiple calls to Stored procedure.

Any suggestions how I can return multiple dataTable/or class objects from MVC to Ajax Call?

e.g: Each Json objects can have a same or different structure
DataTable 1: {Category: “A”, Points:20, Percentage:87} 
        {Category: “B”, Points:20, Percentage:87} 

DataTable 1: {Category: “A”, Spots:20, Percentage:87,ExtraInfo: “NA”} 
        {Category: “B”, Spots:20, Percentage:87,ExtraInfo: “NA”} 

Thanks

1
  • You can only return one JSON string, so have a parameter per data table, eg. [{ dt1: { /* stuff */ }, dt2: { /* stuff */ } }]; Commented Sep 18, 2013 at 10:32

2 Answers 2

1

I am suggesting you to try in this way

[HttpPost]
public JsonResult Action()
    {
        MyClass objMyClass = new MyClass();
        objMyClass.lstTables = new List<System.Data.DataTable>();
        objMyClass.lstTables.Add(new System.Data.DataTable());
        objMyClass.lstTables.Add(new System.Data.DataTable());
        return Json(objMyClass);
    }
    public class MyClass
    {
        public List<System.Data.DataTable> lstTables { get; set; }
    }

Now you can pass n number of tables

Sign up to request clarification or add additional context in comments.

Comments

0

You can return array in one JSON object (do it in application or return one result obkect from database if you like), like:

{
  [
    {data for table 1},
    {data for table 2},
    ...
  ]
}

Or if it different types, like

{
  [
    {ChartType1: Type1, Data: {data for table 1}},
    {ChartType2: Type2, Data: {data for table 2}},
    ...
  ]
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.