CSharp · Mvc
public class Prop{
public string border {set;get;}
}
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>AspNetMvcDemo</title>
<link href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet" />
</head>
<body>
<div>
@Html.Raw(ViewBag.Table)
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$('Table').DataTable();
});
</script>
</body>
</html>
using System;
using System.Web.Mvc;
using System.Collections.Generic;
using HtmlTableHelper;
namespace HelloWorldMvcApp
{
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
var data = new[] { new { Name = "ITWeiHan", Age = "25",Gender = "M" } };
ViewBag.Table = data.ToHtmlTable(new Prop{ border = "1"});
return View();
}
}
}