TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Saminda Kotinkaduwa
NA
40
12.1k
MVC and Ajax datatable with JSON
Jun 29 2018 5:27 AM
Hi Sir,
I have a controller which sends json data to a view and the view supposed to grab that json data and display in the datatable Ajax. but instead view is displaying just RAW json data.
my Controller code is -
public
ActionResult Index2()
{
using
(Model_Test dbObj =
new
Model_Test())
{
List<Test_Table> testList = dbObj.Test_Table.ToList<Test_Table>();
var obj =
new
{ data = testList };
return
Json(obj, JsonRequestBehavior.AllowGet);
}
}
my View code is -
@{
ViewBag.Title =
"Index"
;
Layout =
"~/Views/Shared/_Layout.cshtml"
;
}
<br />
<br />
<table id=
"abc"
class
=
"display"
>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Address</th>
</tr>
</thead>
</table>
<br />
<br />
<link href=
"~/Content/jquery.dataTables.min.css"
rel=
"stylesheet"
/>
@section Scripts{
<script src=
"~/Scripts/jquery.dataTables.min.js"
></script>
<script>
$(document).ready(
function
() {
$(
'#abc'
).DataTable({
"ajax"
: {
"url"
:
"/Test_Table/Index2"
,
"type"
:
"GET"
,
"datatype"
:
"json"
},
"columns"
: [
{
"data"
:
"Id"
,
"autoWidth"
:
true
},
{
"data"
:
"Name"
,
"autoWidth"
:
true
},
{
"data"
:
"Address"
,
"autoWidth"
:
true
}
]
});
});
</script>
}
I tested the datatable with static data and it works fine. so it should be something to do with controller json output. Please help me I am so stuck.
Thanks
Reply
Answers (
3
)
Add items to share point
Hi guys is there any scope for Test driven development ? ?