Это мои / Книги / userHome просмотр:
@model CSBSTest.Models.tbl_Book
@{
ViewBag.Title = "UserHome";
Layout = "~/Views/Shared/_Profile.cshtml";
}
<h2>Books for sale by CUST Students</h2>
<br />
<br />
<table id="books" class="table table-bordered table-hover">
<thead>
<tr>
<th>Id</th>
<th>Book Name</th>
<th>Author</th>
<th>Version</th>
</tr>
</thead>
<tbody></tbody>
</table>
@section scripts
{
<script>
$(document).ready( function () {
var dataTable = $("#books").DataTable({
ajax: {
url: "/Book/GetBooks",
dataSrc: ""
},
columns: [
{
data:"Id"
},
{
data: "Name"
},
{
data: "Author"
},
{
data: "Version"
}
]
});
});
</script>
}
Я звоню / Книги / GetBooks, как показано ниже:
public ActionResult UserHome()
{
return View();
}
public ActionResult GetBooks()
{
var list = _context.tbl_Book.ToList();
return Json(list, JsonRequestBehavior.AllowGet);
}
GetBooks возвращает результат json, который вызывается из раздела сценариев UserHome, как показано выше. Я хочу заполнить список, возвращаемый / Books / GetBooks, в виде данных jquery, но он дает следующее исключение:
.
любая помощь будет высоко оценена заранее.