1.首先新建一个空的Asp.net core项目

2.新建一个类    gj.cs

public class gj
{
// <summary>
/// 主键
/// </summary>
public int id { get; set; } /// <summary>
/// 标题
/// </summary>
public string method { get; set; }
/// <summary>
/// 内容
/// </summary>
public string text { get; set; } public string type { get; set; }
}

3.添加数据库上下文类。

public class DbGj:DbContext
{
public DbSet<gj> gj { set; get; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseMySQL(@"Server=localhost;database=testapp;uid=root;pwd=woshishui");
}

4.添加控制器

public class GJController : Controller
{ public IActionResult Index()
{
using (var db = new DbGj())
{
var lis = db.Set<gj>().ToList();
return View(lis);
} } }

5.视图

@model IEnumerable<CoreTest_1.Models.gj>

@{
ViewData["Title"] = "Index";
} <h1>Index</h1> <p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.method)
</th>
<th>
@Html.DisplayNameFor(model => model.text)
</th>
<th>
@Html.DisplayNameFor(model => model.type)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.method)
</td>
@*<td>
@Html.DisplayFor(modelItem => item.text)
</td>*@
<td>
@Html.DisplayFor(modelItem => item.type)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.id">Edit</a> |
<a asp-action="Details" asp-route-id="@item.id">Details</a> |
<a asp-action="Delete" asp-route-id="@item.id">Delete</a>
</td>
</tr>
}
</tbody>
</table>

F5运行程序 (如图)

最新文章

  1. J2EE、J2SE、J2ME是什么意思?
  2. HTTP协议学习---(九)cookie
  3. Linq操作
  4. OC3-xml文件解析
  5. Python学习笔记整理(四)Python中的字符串..
  6. node.js介绍
  7. Gcc 命令大全
  8. 百度ueditor的图片上传,前后端交互使用
  9. python的文件读写笔记
  10. 一文让你彻底理解 Java NIO 核心组件
  11. 进程间通信IPC-信号
  12. MT【181】横穿四象限
  13. poj3436 ACM Computer Factory, 最大流,输出路径
  14. [原]unity3d GLSL无法pc上显示
  15. python 继承与多重继承
  16. 基于HTML5 Canvas粒子效果文字动画特效
  17. Scrum立会报告+燃尽图 03
  18. DSP5509的中断学习-第4篇
  19. 在u-boot中添加命令
  20. springmvc使用实体參数和ServletAPI

热门文章

  1. 最常见Linux操作
  2. Java多线程编程核心技术-第1章-Java多线程技能-读书笔记
  3. centos7删除Apache组件
  4. btcWallet系列之一-grpc模块
  5. springMVC学习2
  6. Spring Cloud微服务安全实战_2-1_开发环境
  7. day 14
  8. bat 文件追加
  9. 提取文件中的每一个mask,并将mask命名为文件名字
  10. gcc 在c代码中内嵌汇编调用c函数: 只是证明曾经我来过