Jquery Datatable in MVC
This is my controller Action
Controller Action
public ActionResult Retrieving()
{
var data= db.retrieve();
return Json(new { data = data },JsonRequestBehavior.AllowGet);
}
Iam trying to call this method using jquery datatable
This is my view page and i wrote jquery code and also placed jquery
plugins.
@{
ViewBag.Title = "RetrievingSwAssets";
Layout = "~/Views/Shared/_Admin.cshtml";
}
RetrievingSwAssets
//table
datatable links
rel="stylesheet" />
jquery datatable links
@section Scripts{
$(document).ready(function () {
$('#RetrievingSwAst').DataTable({
"ajax": {
//path
"url": "/Admin/Retrieving",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "AssetID", "autoWidth": true },
{ "data": "AMSSW_AssetName", "autoWidth": true },
{ "data": "AMSSW_AssetType", "autoWidth": true },
{ "data": "AMSSW_Vendor", "autoWidth": true },
{ "data": "AMSSW_Version", "autoWidth": true },
{ "data": "Date_of_purchase", "autoWidth": true },
{ "data": "CompanyLocation", "autoWidth": true },
]
});
});
}
But Its Retrieving json format.
Like:{"data":[{"AssetID":"SW-Asset-
1","AMSSW_AssetName":null,"AMSSW_AssetType":"Software Asset","AMSSW_Vendor":null,"AMSSW_Version":null,"Date_of_purchase":null,"CompanyLocation":null},{"AssetID":"SW-Asset-2","AMSSW_AssetName":null,"AMSSW_AssetType":"Software Asset","AMSSW_Vendor":null,"AMSSW_Version":null,"Date_of_purchase":null,"CompanyLocation":null},{"AssetID":"SW-Asset-3","AMSSW_AssetName":"VisualStudio 2017","AMSSW_AssetType":"Software Asset","AMSSW_Vendor":"Micrsoft","AMSSW_Version":"15.2","Date_of_purchase":"2018-06-13","CompanyLocation":"hyd"}]}
I want to display this data in Table format
I don't no where the mistake. Plz solve it...
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sankeerth MaragantiPosted Jun 24, 2018, 9:45 AM
Dharmraj ThakurPosted Jun 21, 2018, 5:57 AM