Datatables warning: JSON Data - Using MVC and LINQ as server side data
Datatables warning: JSON Data - Using MVC and LINQ as server side data
Hi all,
I need to use MVC/LINQ to provide the server side data for my datatables. How do I change the following controller to work?
[code]
public ActionResult Index()
{
var histories = db.Histories.Include(a => a.ActivityType);
return View(histories.ToList());
}
[/code]
I have seen this, but don't know how to include my data:
[code]
public class HomeController : Controller {
[HttpPost]
public ActionResult GetDataTables(DataTable dataTable) {
List table = new List();
//Do something with dataTable and fill table
return new DataTableResult(dataTable, table.Count, table.Count, table);
}
}
[/code]
I need to use MVC/LINQ to provide the server side data for my datatables. How do I change the following controller to work?
[code]
public ActionResult Index()
{
var histories = db.Histories.Include(a => a.ActivityType);
return View(histories.ToList());
}
[/code]
I have seen this, but don't know how to include my data:
[code]
public class HomeController : Controller {
[HttpPost]
public ActionResult GetDataTables(DataTable dataTable) {
List table = new List();
//Do something with dataTable and fill table
return new DataTableResult(dataTable, table.Count, table.Count, table);
}
}
[/code]
This discussion has been closed.
Replies
Allan
[code]
// Rows is a List
StringBuilder sb = new StringBuilder("{\"aaData\":[ ");
for (int i = 0; i <= Rows.Count() - 1; i++)
{
sb.Append("{");
// Add each column's data
sb.Append(Rows[i]);
if (i < Rows.Count - 1)
{
sb.Append("},");
}
else
{
sb.Append("}");
}
sb.Append("]}");
}
return sb.ToString();
[/code]