---
# System prepended metadata

title: '`ASP.NET Core` Razor Pages 最小限のプログラム 2021-09-07'
tags: [最小限のプログラム, Razor, Razor Pages, ASP.NET Core]

---

---
lang: ja-jp
breaks: true
---
# 

## 空のプロジェクトからの変更

![](https://i.imgur.com/oldMGmI.png)

## Startup.cs

```csharp=
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseRouting();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapRazorPages();
        });
    }
}
```

## Pages/_ViewStart.cshtml

```htmlembedded=
@{
    Layout = "_Layout";
}
```

## Pages/Shared/_Layout.cshtml

```htmlembedded=
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="utf-8" />
</head>
<body>
@RenderBody()
</body>
</html>
```

## Pages/Index.cshtml

```htmlembedded=
@page
@model WebApplication18.Pages.IndexModel
@{

}

<div>
    <h1>Welcome</h1>
</div>
```

```csharp=
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace WebApplication18.Pages
{
    public class IndexModel : PageModel
    {
        public void OnGet()
        {
        }
    }
}
```

:::info
デフォルトで、`Pages/Index.cshtml` があればその内容が出力される。
:::

## 実行

![](https://i.imgur.com/f7dHRV5.png)

