如何解决尝试在 chrome 浏览器中显示 jquery 数据表
我正在尝试在 Chrome 浏览器上显示数据表。但是我无法在浏览器中看到它们。 这是我的代码文件。
模型/Author.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EmployeeMvc.Models
{
public class Author
{
public int AuthorId { get; set; }
public String FirstName { get; set; }
public String LastName { get; set; }
public String Position { get; set; }
public String Office { get; set; }
public DateTime StartDate { get; set; }
public decimal Salary { get; set; }
}
public class Book
{
public int BookId { get; set; }
public String BookName { get; set; }
public String Genre { get; set; }
//Foreign Keys
public int AuthorId { get; set; }
//Navigation Property
public Author Author { get; set; }
}
}
模型/AuthorContext.cs
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using EmployeeMvc.Models;
namespace EmployeeMvc.Models
{
public class AuthorContext : DbContext
{
}
}
视图/作者/Author.cshtml
@{
ViewBag.Title = "Author";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Author</h2>
<h2> JQuery datatable server side sorting and pagination in ASP.NET EmployeeMvc </h2>
<div style="width:90%; margin:0 auto;">
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>StartDate</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>StartDate</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
</div>
@* Load Datatable CSS*@
<link href="https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css" rel="stylesheet" />
@section Scripts
{
@* Load Datatable js here*@
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$('#example').DataTable
({
"processing": true,"serverSide": true,"ajax":
{
"url": "/home/LoadData","type": "POST","datatype": "json"
},{
"draw": 1,"recordsTotal": 57,"recordsFiltered": 57,"data": [
[
"Airi","Satou","Accountant","Tokyo","28th Nov 08","$162,700"
],[
"Angelica","Ramos","Chief Executive Officer (CEO)","London","9th Oct 09","$1,200,000"
],[
"Ashton","Cox","Junior Technical Author","San Francisco","12th Jan 09","$86,[
"Bradley","Greer","Software Engineer","13th Oct 12","$132,[
"Brenden","Wagner","7th Jun 11","$206,850"
],[
"Brielle","Williamson","Integration Specialist","New York","2nd Dec 12","$372,[
"Bruno","Nash","3rd May 11","$163,500"
],[
"Caesar","Vance","Pre-Sales Support","12th Dec 11","$106,450"
],[
"Cara","Stevens","Sales Assistant","6th Dec 11","$145,600"
],[
"Cedric","Kelly","Senior Javascript Developer","Edinburgh","29th Mar 12","$433,060"
]
]
});
});
</script>
}
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application,please visit
https://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration,visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="AuthorContext" connectionString="Data Source=(LocalDB)\MSsqlLocalDB;AttachDbFilename=C:\Users\SHASHANKSHEKHAR\source\repos\EmployeeMvc\App_Data\BookDB.mdf;Integrated Security=True"/>
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.8" />
<httpRuntime targetFramework="4.8" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Linq.Dynamic.Core" publicKeyToken="0f07ec44de6ac832" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.7.0" newVersion="1.2.7.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<providers>
<provider invariantName="System.Data.sqlClient" type="System.Data.Entity.sqlServer.sqlProviderServices,EntityFramework.sqlServer" />
</providers>
</entityFramework>
<system.codedom>
<compilers>
<compiler extension=".cs" language="c#;cs;csharp" warningLevel="4" compilerOptions="/langversion:7.3 /Nowarn:1659;1699;1701;612;618" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,Microsoft.CodeDom.Providers.DotNetCompilerPlatform,Version=3.6.0.0,PublicKeyToken=31bf3856ad364e35" />
<compiler extension=".vb" language="vb;vbs;visualbasic;vbscript" warningLevel="4" compilerOptions="/langversion:default /Nowarn:41008,40000,40008 /define:_MYTYPE=\"Web\" /optionInfer+" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider,PublicKeyToken=31bf3856ad364e35" />
</compilers>
</system.codedom>
</configuration>
控制器/AuthorController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace EmployeeMvc.Controllers
{
public class AuthorController : Controller
{
// GET: Author
public ActionResult Author()
{
return View();
}
}
}
迁移/配置.cs
namespace EmployeeMvc.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<EmployeeMvc.Models.AuthorContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(EmployeeMvc.Models.AuthorContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data.
}
}
}
迁移/202102020902141_InitialCreate.cs
namespace EmployeeMvc.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class InitialCreate : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
}
- 作者表
CREATE TABLE [dbo].[Author] (
[Id] INT NOT NULL,[FirstName] NVARCHAR (50) NOT NULL,[LastName] NVARCHAR (50) NOT NULL,[Position] NVARCHAR (50) NOT NULL,[Office] NVARCHAR (50) NOT NULL,[StartDate] DATETIME NOT NULL,[Salary] DECIMAL (18) NOT NULL,PRIMARY KEY CLUSTERED ([Id] ASC)
);
书桌
CREATE TABLE [dbo].[Books] (
[Id] INT NOT NULL,[Position] INT NOT NULL,PRIMARY KEY CLUSTERED ([Id] ASC)
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。