Вот мой _layout.cshtml Извините, если мои коды слишком длинныпредставление таблицы не работает .. Вот мой контроллер с именем BookController. Я использовал хранимую процедуру в этой операции. Обратите внимание, что другие объекты данных, не включенные, чтобы сделать код короче
// GET: Book
public ActionResult Index()
{
return View();
}
public ActionResult booksView()
{
var data = viewAllBooks();
List<BookModel> showAllBooks = new List<BookModel>();
if (data != null)
{
if (data.Rows.Count > 0)
{
foreach (DataRow row in data.Rows)
{
showAllBooks.Add(new BookModel()
{
bookTitle = row["bookTitle"].ToString(),
authorName = row["Author"].ToString(),
ISBN = row["ISBN"].ToString()
//other data
});
}
}
}
return Json(new { records = showAllBooks }, JsonRequestBehavior.AllowGet);
}
здесьмой индексный указатель
<table id="booksTable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Image</th>
<th>Book Tittle</th>
<th>Book Author</th>
<th>ISBN</th>
<th>Category</th>
<th>DDC</th>
<th>Publish Place</th>
<th>Publish Date</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
</table>
@Styles.Render("~/Content/DataTables/css")
@section scripts{
@Scripts.Render("~/bundles/DataTables/js")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/javascript")
}
Ниже приведен дополнительный набор файлов js и css, например, и т. д., которые не включают в себя сокращение кода
public static void RegisterBundles(BundleCollection bundles)
{
/////////////////////// Script Bundles ///////////////////////////
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new ScriptBundle("~/bundles/DataTables/js").Include(
"~/Scripts/DataTables/media/js/dataTables*",
"~/Scripts/DataTables/media/js/jquery*"));
bundles.Add(new ScriptBundle("~/bundles/javascript").Include(
"~/Scripts/JavaScript.js"));
/////////////////////////////// Style Bundles ////////////////////////////
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.lumen.css",
"~/Content/bootstrap.css",
"~/Content/Site.css"));
bundles.Add(new StyleBundle("~/Content/DataTables/css").Include(
"~/content/DataTables/media/css/dataTables*",
"~/content/DataTables/media/css/jquery*"));
}
последний код - мой файл javascript, который входит в комплект
$(document).ready(function () {
$('#booksTable').DataTable(
{
"ajax": {
"url": "/Book/booksView",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "records": "" },
{ "records": "bookTitle" },
{ "records": "authorName" },
{ "records": "ISBN" },
{ "records": "Category" },
{ "records": "DDC" },
{ "records": "pubPlace" },
{ "records": "pubDate" }
]
});
});