動くコード図鑑技術記事現場の渡り方キャリア論すべての記事About
C#

ミニマム検証— 3段階の最小Action

出典: Controller は WinForms の Form_Load 拡張版だと理解する — ASP.NET MVC 5 業務SE 入門ミニマム検証— 3段階の最小Action

ミニマム検証— 3段階の最小Action (csharp)#5401e74f3850
// ✅ Step 1:一番シンプル— Helloを返すだけ
public class HelloController : Controller
{
    public ActionResult Index()
    {
        return Content("Hello, World!");   //文字列をそのまま返す
    }
}
 
// ✅ Step 2:引数を受け取るAction
public ActionResult Greet(string name)
{
    // /Hello/Greet?name=Bobで呼ばれると"Hello, Bob!"を返す
    return Content($"Hello, {name}!");
}
 
// ✅ Step 3: Modelを返すAction
public ActionResult Show()
{
    var model = new GreetingVm { Name = "World", Message = "Hello, MVC!" };
    return View(model);   // View側で@Model.Name / @Model.Messageを表示
}
▸ この snippet は実行結果未収録
▸ 実行結果は未収録です
  • id: #5401e74f3850
  • lines: 22
  • extracted: 2026-06-10

Source収録記事

この snippet は記事の「ミニマム検証— 3段階の最小Action」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。

同じ記事から

8
図鑑トップ