반응형
ASP.NET으로 웹 개발 시 Form에서 Controller로 데이터를 넘기는 방식은 Spring과 매우 유사하다.
다음의 간단한 예제로 바로 이해할 수 있다.
[Route("[controller]/[action]")]
public class TestController : Controller
{
..
// form 화면 이동
public IActionResult testForm()
{
return View();
}
[HttpPost]
public IActionResult testForm(string userId, int age)
{
Console.WriteLine("userId = " + userId);
Console.WriteLine("age = " + age);
return Redirect("/test/testView");
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
</head>
<body>
<form method="POST" action="/test/testForm">
<input type="text" name="userId" />
<input type="text" name="age" />
<input type="submit" name="제출" />
</form>
</body>
</html>
728x90
반응형
'Backend 개발 > .NET' 카테고리의 다른 글
[Layered Architecture] ASP.NET (0) | 2025.06.17 |
---|---|
Entity Framework Core vs ADO.NET 간단 정리 (0) | 2025.06.10 |
ASP.NET Master Page(혹은 Layout) (0) | 2025.06.05 |
ASP.NET [ViewData, ViewBag, ViewModel] 비교 (0) | 2025.05.26 |
ASP.NET Controller 에서 View로 데이터 전달하는 방법 (0) | 2025.05.22 |