
ASP.NET MVC Framework - Model

ASP.NET MVC Framework - Model
MVC:Model-View-Controller 軟體設計模式
其中包含以下三大面向:
Controller:從 Model 拿資料再將其提供給 View
View用:呈現使者看到的畫面
- Model:處理商業邏輯,提供資料
Model
在專案的方案總管中 Model 的資料夾上按右鍵,選擇 加入 -> 類別 -> 類別 Visual C#,並替 Model 命名

Model Modify
可以在 Model 裡寫一些 function 提供資料給 Controller 和 View
1 | namespace MVC_Project.Models |
Controller Modify
接著修改 Controller 接收來自 Model 的參數
1 | namespace MVC_Project.Controllers |
Execute
run 起來後出現以下頁面,此時可看見畫面中有由 @ViewBag.Label 從 Controller 裡獲得的來自 Model 傳值的 “Hello World !!!” 字串
