MVC Controller 負責處理瀏覽器請求,URL 透過路由對應特定 Controller。
System.Web.Mvc.Controller 基類,獲得實用方法xxxController (如 ProductController)ProductController
public class ProductController : Controller {
public ActionResult Index() {
// Action 邏輯
throw new NotImplementedException();
}
}
Controller 基類提供 View()、Redirect()、Json()、Content() 等輔助方法回傳不同 ActionResult。
https://localhost/Product/Index/3 → 對應 ProductController.Index(id=3)
Action 負責:執行商業邏輯、操作 Model、選擇回傳 View 或重導向。