C# ASP.NET Core开发 001.001

Visual studio Code

  1. 去官网安装.NET Core SDK
  2. cmd
dotnet new console --name HelloSSharp
  1. download Visual studio code
  2. 选中project文件夹右击, open with code
using System;
using System.IO;

namespace HelloSSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var stream = File.Create(@"E:\CSharbProject\HelloSSharp\test.txt");
            var writer = new StreamWriter(stream);

            Console.WriteLine("Hello World!");
            writer.WriteLine("1231");
            writer.Flush();
            writer.Close();
        }
    }
}

Visual studio 2019

  1. 创建一个Web Application model view controller
  2. add model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication1.Models
{
    public class Student
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
}

  1. add controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace WebApplication1.Controllers
{
    public class StudentController : Controller
    {
        // GET: /<controller>/
        public IActionResult Index()
        {

            
            var Students = new List<Student>
            {
                new Student { ID = 1, Name = "adfa" },
                
                new Student { ID = 2, Name = "adfa" },
    
                new Student { ID = 3, Name = "adfa" },

                new Student { ID = 4, Name = "adfa" },
    
                new Student { ID = 5, Name = "adfa" }
            };
            return View(Students);
        }
    }
}

  1. 右击 add view
    Template - model
    框架自动生成前端代码
@model IEnumerable<WebApplication1.Models.Student>

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
<p>
    <a asp-action="Create">Create New</a>
</p>
<table class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.ID)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Name)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
@foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.ID)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
                @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
                @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
            </td>
        </tr>
}
    </tbody>
</table>
</body>
</html>

  1. 运行
http://localhost:53819/student
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值