绫木口,染发剂怎么用,yoee
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运行程序 (如图)
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论