C# ASP.NET Core開発001.001
3416 ワード
Visual studio Code は公式サイトにインストールします.NET Core SDK cmd download Visual studio code プロジェクトフォルダを選択右クリックopen with code
Visual studio 2019 Webアプリケーションモデルview controller を作成 add model add controller 右クリックadd view Template-modelフレームワーク自動生成フロントエンドコード 運転
dotnet new console --name HelloSSharp
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
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; }
}
}
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: //
public IActionResult Index()
{
var Students = new List
{
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);
}
}
}
@model IEnumerable
@{
Layout = null;
}
Index
@foreach (var item in Model) {
}
@Html.DisplayNameFor(model => model.ID)
@Html.DisplayNameFor(model => model.Name)
@Html.DisplayFor(modelItem => item.ID)
@Html.DisplayFor(modelItem => item.Name)
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
http://localhost:53819/student