I am using Ajax Datatable, I want to feed the table with Json data, which i am returning from MVC Action method. This is what i have tried so far,
My Controller action method
public ActionResult Index()
{
_dbcontext = new dbContext();
List<Employee> employees = new List<Employee>();
var query = (from e in _dbcontext.Employees select new { e.FirstName, e.LastName, e.Username, e.Password }).ToList();
return Json(query,JsonRequestBehavior.AllowGet);
}
And here is my Javascript on Index page
</script>
$(document).ready(function () {
$('#example').dataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "Home/Index",
"dataType": "jsonp"
}
});
});
</script>
But on page load only the plain Json data can be seen and no data table, I think It is not even rendering the Html on the index page and hence neither Datatable as I can not see anything in chrome debugger.
Also, Html and script referencing is all Ok as I can see the results when I feed the datatable from a .txt file having array of data.
I don't know what is the right way to do that, If somebody has the solution for that, then please help, Thanks.