
ไฟล์
$(document).ready(function() {
$.ajax({
type: "POST",
url: '/Home/ViewData/',
datatype: "json",
contentType: "application/json: charset=utf-8",
data: JSON.stringify({}),
success: function (json1) {
debugger
var tableload = json1.html;
var dataset = eval("[" + tableload + "]");
$('#ViewValues').DataTable({
"bDestroy": true,
data: dataset,
columns: [
{ title: "ID" },
{ title: "First Name" },
{ title: "Last Name" },
{ title: "Mobile Number" },
{ title: "Address" },
]
});
},
failure: function (errMsg) {
alert(errMsg);
}
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
<script src="">https://cdn.datatables.net/1.12.1/js/dataTables.bootstrap4.min.js</script>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
รบกวนผู้รู้หน่อยครับ ตารางมันทำให้เป็นขนาดปกติไม่ได้ครับ
ไฟล์
$.ajax({
type: "POST",
url: '/Home/ViewData/',
datatype: "json",
contentType: "application/json: charset=utf-8",
data: JSON.stringify({}),
success: function (json1) {
debugger
var tableload = json1.html;
var dataset = eval("[" + tableload + "]");
$('#ViewValues').DataTable({
"bDestroy": true,
data: dataset,
columns: [
{ title: "ID" },
{ title: "First Name" },
{ title: "Last Name" },
{ title: "Mobile Number" },
{ title: "Address" },
]
});
},
failure: function (errMsg) {
alert(errMsg);
}
});
});
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
<script src="">https://cdn.datatables.net/1.12.1/js/dataTables.bootstrap4.min.js</script>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>