当前位置: 首页 > news >正文

谷建网站建设模板青岛网站制作计划

谷建网站建设模板,青岛网站制作计划,娱乐新闻做的好的网站,手机网站开发方式在VSCore中的页面的增删改查(以Blog项目为例) 1.创建项目(无解决方案)复杂项目才需要 dotnet new mvc -o Blog2.控制器 BlogsController.cs 控制器(Controller)名字和视图(View)中的文件名要一模一样 u…

在VSCore中的页面的增删改查(以Blog项目为例)

1.创建项目(无解决方案)复杂项目才需要

dotnet new mvc -o Blog

2.控制器 BlogsController.cs

  • 控制器(Controller)名字和视图(View)中的文件名要一模一样
using Microsoft.AspNetCore.Mvc;
//Blog项目名 Models中有新建文件需要引用
using Blog.Models;
//Blog项目名
namespace Blog.Controllers;
//BlogsController跟控制器名字取的一样
public class BlogsController : Controller
{// 返回视图  用于整个页面public IActionResult Index(){return View(Db.Blogs);}// 增加页面public IActionResult Increase(){return View();}//  编辑页面public IActionResult Redact(){return View();}// 删除页面public IActionResult Delete(){return View();}
}

3. _ViewStart.cshtml中的默认模板页面可改为空(选择)

@{Layout = null;
}

4. 在View中

  • 控制器(Controller)名字和视图(View)中的文件名要一模一样
    1. 创建文件夹Blogs
    1. 创建文件Index.cshtml

5. 在Properties中(选择)

  • launchSettings.json 中端口可改为5000

6. 在4.中的Index.cshtml中写需要的内容页面

7. 在wwwroot中写css文件(如需css文件的话)

  • css文件名为base.css
  • link在Index.cshtml页面中书写
<link rel="stylesheet" href="~/css/base.css">

8. 在Models中创建Blogs.cs 模型

  • 字段名
  • Blogs.cs中
namespace Blog.Models;public class Blogs
{public int Id{get;set;}public string Title{get;set;}=null!;public string Content{get;set;}=null!;public string Author{get;set;}=null!;}

9. 在Models中创Db.cs(模拟数据库创建)

  • 静态字段
  • Db.cs中
namespace Blog.Models;
public static class Db
{// 集合public static List<Blogs> Blogs{get;set;}// 构造函数static Db(){Blogs=[];for (var i = 1; i <=10; i++){var tmp = new Blogs{Id=i,Title=$"永远是朋友{i}",Content=$"假日风情{i}",Author="哈哈"};Blogs.Add(tmp);}}
}

10. 在Index.cshtml中

  • 增删改查需要跳转的页面就改换位a标签
    • input(button) --》 改换成a标签
  • asp-action可以跳转到书写的页面
  • Increase 是在Views下的Blogs中创建的Increase.cshtml
    <a asp-action="Increase">增加</a>

11. 在Models中写的Db.cs

  • 记得在控制器BlogsController.cs中返回视图
   public IActionResult Index(){return View(Db.Blogs);}

完整版

1. 在Controllers需要写的文件

  • BlogsController.cs中
using Microsoft.AspNetCore.Mvc;
using Blog.Models;
namespace Blog.Controllers;public class BlogsController : Controller
{public IActionResult Index(){return View(Db.Blogs);}public IActionResult Increase(){return View();}public IActionResult Redact(){return View();}public IActionResult Delete(){return View();}
}

2. 在Models中需要写的文件

  • 在Blogs.cs文件中
namespace Blog.Models;public class Blogs
{public int Id{get;set;}public string Title{get;set;}=null!;public string Content{get;set;}=null!;public string Author{get;set;}=null!;}
  • 在Db.cs文件中

namespace Blog.Models;
public static class Db
{public static List<Blogs> Blogs{get;set;}static Db(){Blogs=[];for (var i = 1; i <=10; i++){var tmp = new Blogs{Id=i,Title=$"永远的友谊{i}",Content=$"开心每一天{i}",Author="哈哈"};Blogs.Add(tmp);}}
}

3. Views

  • 在Views下创建一个文件夹 Blogs
  • 在Blogs中创建Index.cs
<link rel="stylesheet" href="~/css/base.css">
@model List<Blog.Models.Blogs><a asp-action="Increase">增加</a>
<table><tr><th>Id</th><th>标题</th><th>内容</th><th>作者</th><th>操作</th></tr>@foreach(var item in @Model){<tr><td>@item.Id</td><td>@item.Title</td><td>@item.Content</td><td>@item.Author</td><td><a asp-action="Redact">编辑</a><a asp-action="Delete">删除</a></td></tr>}
</table>
  • 在Increase.cs文件中
<h2>新增</h2>
<table><form action=""><tr><td>标题</td><td>:</td><td><input type="text"></td></tr><tr><td> 内容</td><td>:</td><td><input type="text"></td></tr><tr><td>作者</td><td>:</td><td><input type="text"></td></tr><tr><td><input type="button" value="保存"></td><td></td><td></td></tr></form>
</table>
  • 在Redact.cshtml文件中
<h2>修改</h2>
<table><form action=""><tr><td>标题</td><td>:</td><td><input type="text" placeholder="永远是朋友"></td></tr><tr><td> 内容</td><td>:</td><td><input type="text" placeholder="真心换一切"></td></tr><tr><td>作者</td><td>:</td><td><input type="text" placeholder="哈哈"></td></tr><tr><td><input type="button" value="保存"></td><td></td><td></td></tr></form>
</table>

4. 在wwwroot中的css

  • 创建base.cs文件
table,
tr,
th,
td{border: 1px solid;border-collapse: collapse;
}th{width: 100px;height: 40px;background-color: paleturquoise;
}
tr{width: 100px;height: 30px;
}
a{display: inline-block;width: 40px;height: 30px;line-height: 30px;text-decoration: none;background-color: rgb(127, 228, 228);color: papayawhip;border: 1px solid;border-radius: 10px;text-align: center;
}
a:nth-child(2){background-color: plum;color: papayawhip;
}

完成完整版的以上步骤后

    1. 可以在进入到Blog文件中运行
      • 热重载
      • dotnet watch
    1. 打开Index页面
      • 指的是在Blogs文件夹中的Index.cshtml文件
      • Index改成Blogs文件下的其他名字就会跳转到对应的页面
      • http://localhost:5212/blogs/index
http://www.yayakq.cn/news/904978/

相关文章:

  • 黑龙江建设网站招聘南京微信网站开发
  • 旅游做攻略用什么网站太原建站服务
  • 自己可以建设网站吗建设学校网站的需求分析
  • 商务网站创建方案php个人网站源码下载
  • 什么网站做任务的q币诚信通旺铺网站建设
  • 请简述网站建设的方法免费发布信息网站大全
  • 网站如何做监控直播wordpress连接数据库错误
  • 深圳网站有哪些内容深圳公司注册地址异常怎么办
  • 做淘宝网站的主机代理网易游戏合作要多少钱
  • 哈尔滨开网站在线玩传奇
  • 网站建设i rsky做网站 所需资源
  • 泰安可信的网站建设网页设计站点
  • 公司网站域名无法解析wordpress配置ip访问不了
  • 网站流量提升方法高端网站建设公司好不好
  • 夜夜做新郎网站在线视频免费下载软件全免费
  • 网站建设申请总结注册公司做网站
  • phpcms网站模版网页内容编辑
  • 网站建设中单页面南昌网站推广策划
  • 天猫网站左侧导航是怎么做的万网做网站吗
  • 上海网站建设类岗位wordpress不能视频
  • 芯片公司网站建设关闭WordPress主题自适应
  • 网站套模板什么意思网页界面设计调查问卷
  • 没有工信部备案的网站是骗子吗一般网站后台地址
  • 陕西网站建设方案wordpress 获取表单数据
  • 外国排版网站wordpress 商品展示
  • 专业网站制作设福州seo代理计费
  • 南京cms建站系统wordpress多站点换域名
  • 做哪个网站零售最好营销型网站建设服务
  • 网站服务器速度对seo有什么影响?外贸站seo
  • 长沙网站seo公司互联网服务平台备案单位机动车