最近开始学习asp net core 这个是个跨平台的Web,console,form 基本啥都可以吧,把微软落下的部分,终于追赶了上来。net core 从2016年开始,到现在已经有3年了,最近3.0已经在测试,可能不稳定,官方暂时推荐sdk用2.2。
我这里新手,也不会写博客,字体没有去搞。格式也没有去搞。想到哪里就写到哪里吧。希望能坚持每隔几天,或者每天都在写自己所学习的内容,和大家一起分享吧。
先截图,这个不可以发视频吗?
这个是我入门刚刚学习的说实话,MVC刚接触有点难,基本花了我快3天的时间我才算知道一点点而已。
我学习的思路是这样子的:
1 主页布局好,每个Demo,独立作为一个功能,单独拿出来,便于以后直接用哦;
2 写一个登录的,这里面没有调用数据库,可以作为入门去理解net core web ;
3 写一个注册的,其实差不多。就搞一个界面出来吧,现在也没有搞数据库;
4 写一个列表的 可以根据读取数据显示
5 访问数据库的
6 websocket客户端可以与server通讯
7 MQTT
8 http
9 UDP
10 开始着手项目了
页面源码我公布下,新手可以看下
Viem/Home/Index.cshtml代码:
@{
ViewData[“Title”] = “主页”;
}
<style>
</style>
<script type="text/javascript">
function jiafa(a, b) {
return a + b;
}
</script>
@* 登录 注册 个人资料 查询 样式:每行一个项目,左边是图标,右边是说明吧 ~/image/denglu.png *@
@
@
wwwroot/css/Home.css 代码如下:
body {
}
.zhengti {
position:fixed;
margin-top:5%;
margin-left:5%;
margin-bottom:5%;
}
.hang{
position:page;
margin-bottom:10px;
margin-top:10px;
border:solid;
border-width:1px;
margin-left:5%;
width:80%;
height:200px;
vertical-align:middle;
}
.hang:hover {
border: 5px solid red;
}
.hang img {
position: absolute;
height: 180px;
width: 180px;
margin-top:10px;
margin-left:10px;
border: none;
/float:left;/
padding: 1px 1px 1px 1px;
}
.hang p {
position: absolute;
text-align:center;
line-height:200px;
font-size: 1em;
height: 200px;
width: 100%;
color: black;
}
Controllers/HomeControlle.cs代码如下:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using mytest.Models;
namespace mytest.Controllers
{
public class HomeController : Controller
{
public static string conf = “Server=localhost;database=mysqlshujuku;uid=root;pwd=175921781;pooling=true;CharSet=utf8;port=3306;sslmode=none”;
public IActionResult Index()
{
//using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(conf)) {
// conn.Open();
//}
//return Content(“”);
return View();
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}