C#
ミニマム検証— 3段階の最小Action
出典: Controller は WinForms の Form_Load 拡張版だと理解する — ASP.NET MVC 5 業務SE 入門 — ミニマム検証— 3段階の最小Action
// ✅ 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 は実行結果未収録
▸ 実行結果は未収録です
Source収録記事
この snippet は記事の「ミニマム検証— 3段階の最小Action」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。
同じ記事から
8 件// ✅ WinForms版: Form_Loadで初期化処理 public partial class CustomerForm : Form { private void CustomerForm_Load(object sender, EventArgs e)未収録
対応1: Form_Load ↔ Index()Action
#d42b77bc5cba
// ✅ ASP.NET MVC版: Index()Actionで同等の処理 public class CustomerController : Controller { public ActionResult Index()未収録
対応1: Form_Load ↔ Index()Action
#dc78e1f93429
// ✅ WinForms版:ボタンクリックでフォーム送信 public partial class SearchForm : Form { private void btnSearch_Click(object sender, EventArgs e)未収録
対応2: btn_Click ↔ POST Action
#8e21b9ee15b3
// ✅ ASP.NET MVC版: POST Actionで同等 public class CustomerController : Controller { private readonly ICustomerService _service;未収録
対応2: btn_Click ↔ POST Action
#de3edf727181
// ✅ WinForms版: DataSource直接代入 private void Form_Load(object sender, EventArgs e) { var list = new List<CustomerVm>未収録
対応3: DataGridView.DataSource ↔ return View(model)
#524489acb479
// ✅ ASP.NET MVC版: return View(model)でModelを渡す public ActionResult Index() { var list = new List<CustomerVm>未収録
対応3: DataGridView.DataSource ↔ return View(model)
#401e976a96e9
