SlideShare a Scribd company logo
ASP.NET MVC
AGENDA
• MVC (Model-View-Control)
• ASP.NET MVC
• 系統開發流程
• 範例實作
• 程式說明
MVC (Model-View-Control)
• What is MVC
– 1979年在smalltalk語言使用
• 資料表現層、商業邏輯層
– Design Pattern(設計樣式) or framework (框架)
– Separation of Concerns (關注點分離)
• Components
– View (檢視)
• 負責使用者介面相關呈現,包括輸入與輸出
– Control (控制器)
• 負責控制系統的流程,決定網頁操作流程,回應用戶端的要求與
錯誤處理
– Model (模型)
• 負責定義資料格式與資料存取介面,包括商業邏輯與資料驗證
The relationship between MVC
主動
被動
1. 顯示出所要開啟的網頁
2. 使用者登入驗證
1
2
3. 內部資料的存取
3
ASP.NET MVC
• View
– HTML/XML/CSS
– JSON
– Javascript (jQuey, JQuery UI, Ext JS,…)
– AJAX
• Control
– ASP.NET Controller
• Model
– ADO.NET
– Entity Framework
– LINQ to SQL
– Database operation
ASP.NET MVC & Web Form
Web Form
• 優點
– 快速開發 (viewstate)
– 不用了解HTML & CSS
• 缺點
– 控制元件不易微調
– 不容易測試
MVC
• 優點
– 簡化複雜度
– 易於分工
– 更容易測試
– 採用同一套開發習慣
• 缺點
– 缺乏元件支援
ASP.NET MVC & Web Form
Web Form
• View based
• Design Flow
– 建立”Order”資料夾
– 建立”addorder.aspx”
– 從工具列拉UI元件
– 連接到datasource
• Example Code
– File structure
– About
– Register/login
MVC
• Controller based
• Design Flow
– URL配置
– Controller對應
– 取得對應的Model
– 將model的資料傳到view
– 實作view
• Example Code
– File structure
– About
– Register/login
系統開發流程
1. 網站規劃
– 網站規畫
– 網站功能
– 資料模型規畫
2. 建立Model
3. 建立Controller
4. 調整View
範例實作 – 網站規劃
• 建立一個可以新增、修改、刪除SNMP設備
的網頁
• 資料庫設計
索引 名稱 資料型別 允許空值 範圍
Key Index int
DeviceName nvarchar(32)
DeviceIP varhar(32)
SNMPVersion int 1 ~ 2
ReadCommunity varchar(32)
WriteCommunity varchar(32)
DeviceType int ●
DeviceStatus int ●
範例實作 – 建立Model
• 選Models-> 右鍵 -> 加入 -> 類別
範例實作 – 建立Model
• DeviceInfo.cs
– 程式碼優先開發模式 (Code First)
– using System.ComponentModel;
– using System.ComponentModel.DataAnnotations;
• [Key]:索引
• [Required]:可否為null
• [DisplayName(“設備名稱”)]:View上面所看到的名稱
• [MaxLength(32)]:最大的字串長度
• [Range(1, 2)]:數值的範圍
範例實作 – 建立Controller
• 選”Controller” ->右鍵 -> 加入 -> 控制器
範例實作 – 調整View
• 將DeviceType與DeviceStatus的欄位隱藏起來
程式說明
• 如何看到Model存放的資料
• RouteConfig.cs
• DeviceInfoController.cs
• Index.cshtml
• Create.cshtml

More Related Content

Similar to ASP.net MVC

2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練42016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
Duran Hsieh
 
twMVC#01 | ASP.NET MVC 的第一次親密接觸
twMVC#01 | ASP.NET MVC 的第一次親密接觸twMVC#01 | ASP.NET MVC 的第一次親密接觸
twMVC#01 | ASP.NET MVC 的第一次親密接觸
twMVC
 
ASP.NET MVC 快速上手
ASP.NET MVC 快速上手ASP.NET MVC 快速上手
ASP.NET MVC 快速上手
Study4TW
 
Introduction to ASP.NET MVC and MVC 5 Features
Introduction to ASP.NET MVC and MVC 5 FeaturesIntroduction to ASP.NET MVC and MVC 5 Features
Introduction to ASP.NET MVC and MVC 5 FeaturesJeff Chu
 
ASP.NET MVC Model 的設計與使用 twMVC#10
ASP.NET MVC Model 的設計與使用 twMVC#10ASP.NET MVC Model 的設計與使用 twMVC#10
ASP.NET MVC Model 的設計與使用 twMVC#10
twMVC
 
twMVC#10 | ASP.NET MVC Model 的設計與使用
twMVC#10 | ASP.NET MVC Model 的設計與使用twMVC#10 | ASP.NET MVC Model 的設計與使用
twMVC#10 | ASP.NET MVC Model 的設計與使用
twMVC
 
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練3
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練32015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練3
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練3
Duran Hsieh
 
與 Asp.net mvc 的第一次親密接觸 - twMVC#1
與 Asp.net mvc 的第一次親密接觸 - twMVC#1與 Asp.net mvc 的第一次親密接觸 - twMVC#1
與 Asp.net mvc 的第一次親密接觸 - twMVC#1
twMVC
 
Ch13 整合Spring MVC
Ch13  整合Spring MVC Ch13  整合Spring MVC
Ch13 整合Spring MVC
Justin Lin
 
Vlog02 [eng sub]什麼是controller和如何在asp.net核心中創建controller?-what is controller ...
Vlog02  [eng sub]什麼是controller和如何在asp.net核心中創建controller?-what is controller ...Vlog02  [eng sub]什麼是controller和如何在asp.net核心中創建controller?-what is controller ...
Vlog02 [eng sub]什麼是controller和如何在asp.net核心中創建controller?-what is controller ...
SernHao TV
 
Ch13 整合 Spring MVC/Security
Ch13 整合 Spring MVC/SecurityCh13 整合 Spring MVC/Security
Ch13 整合 Spring MVC/Security
Justin Lin
 
ASP NET MVC
ASP NET MVC ASP NET MVC
ASP NET MVC
leeju lee
 
Mvc 架构
Mvc 架构Mvc 架构
Mvc 架构cyla993
 
Real World ASP.NET MVC
Real World ASP.NET MVCReal World ASP.NET MVC
Real World ASP.NET MVC
jeffz
 
ASP.Net MVC2 简介
ASP.Net MVC2 简介ASP.Net MVC2 简介
ASP.Net MVC2 简介Allen Lsy
 
ASP.NET MVC简介
ASP.NET MVC简介ASP.NET MVC简介
ASP.NET MVC简介
Du Wanzhi
 
Asp.net+mvc4框架揭秘
Asp.net+mvc4框架揭秘Asp.net+mvc4框架揭秘
Asp.net+mvc4框架揭秘Zhenhua Tang
 
ASP.NET MVC The Begining
ASP.NET MVC The BeginingASP.NET MVC The Begining
ASP.NET MVC The Begining
Simon Huang
 
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有Wade Huang
 

Similar to ASP.net MVC (20)

2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練42016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
 
twMVC#01 | ASP.NET MVC 的第一次親密接觸
twMVC#01 | ASP.NET MVC 的第一次親密接觸twMVC#01 | ASP.NET MVC 的第一次親密接觸
twMVC#01 | ASP.NET MVC 的第一次親密接觸
 
ASP.NET MVC 快速上手
ASP.NET MVC 快速上手ASP.NET MVC 快速上手
ASP.NET MVC 快速上手
 
Introduction to ASP.NET MVC and MVC 5 Features
Introduction to ASP.NET MVC and MVC 5 FeaturesIntroduction to ASP.NET MVC and MVC 5 Features
Introduction to ASP.NET MVC and MVC 5 Features
 
ASP.NET MVC Model 的設計與使用 twMVC#10
ASP.NET MVC Model 的設計與使用 twMVC#10ASP.NET MVC Model 的設計與使用 twMVC#10
ASP.NET MVC Model 的設計與使用 twMVC#10
 
twMVC#10 | ASP.NET MVC Model 的設計與使用
twMVC#10 | ASP.NET MVC Model 的設計與使用twMVC#10 | ASP.NET MVC Model 的設計與使用
twMVC#10 | ASP.NET MVC Model 的設計與使用
 
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練3
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練32015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練3
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練3
 
與 Asp.net mvc 的第一次親密接觸 - twMVC#1
與 Asp.net mvc 的第一次親密接觸 - twMVC#1與 Asp.net mvc 的第一次親密接觸 - twMVC#1
與 Asp.net mvc 的第一次親密接觸 - twMVC#1
 
Ch13 整合Spring MVC
Ch13  整合Spring MVC Ch13  整合Spring MVC
Ch13 整合Spring MVC
 
Vlog02 [eng sub]什麼是controller和如何在asp.net核心中創建controller?-what is controller ...
Vlog02  [eng sub]什麼是controller和如何在asp.net核心中創建controller?-what is controller ...Vlog02  [eng sub]什麼是controller和如何在asp.net核心中創建controller?-what is controller ...
Vlog02 [eng sub]什麼是controller和如何在asp.net核心中創建controller?-what is controller ...
 
Asp.Net Mvc 1.0
Asp.Net Mvc 1.0Asp.Net Mvc 1.0
Asp.Net Mvc 1.0
 
Ch13 整合 Spring MVC/Security
Ch13 整合 Spring MVC/SecurityCh13 整合 Spring MVC/Security
Ch13 整合 Spring MVC/Security
 
ASP NET MVC
ASP NET MVC ASP NET MVC
ASP NET MVC
 
Mvc 架构
Mvc 架构Mvc 架构
Mvc 架构
 
Real World ASP.NET MVC
Real World ASP.NET MVCReal World ASP.NET MVC
Real World ASP.NET MVC
 
ASP.Net MVC2 简介
ASP.Net MVC2 简介ASP.Net MVC2 简介
ASP.Net MVC2 简介
 
ASP.NET MVC简介
ASP.NET MVC简介ASP.NET MVC简介
ASP.NET MVC简介
 
Asp.net+mvc4框架揭秘
Asp.net+mvc4框架揭秘Asp.net+mvc4框架揭秘
Asp.net+mvc4框架揭秘
 
ASP.NET MVC The Begining
ASP.NET MVC The BeginingASP.NET MVC The Begining
ASP.NET MVC The Begining
 
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有
 

ASP.net MVC

  • 2. AGENDA • MVC (Model-View-Control) • ASP.NET MVC • 系統開發流程 • 範例實作 • 程式說明
  • 3. MVC (Model-View-Control) • What is MVC – 1979年在smalltalk語言使用 • 資料表現層、商業邏輯層 – Design Pattern(設計樣式) or framework (框架) – Separation of Concerns (關注點分離) • Components – View (檢視) • 負責使用者介面相關呈現,包括輸入與輸出 – Control (控制器) • 負責控制系統的流程,決定網頁操作流程,回應用戶端的要求與 錯誤處理 – Model (模型) • 負責定義資料格式與資料存取介面,包括商業邏輯與資料驗證
  • 4. The relationship between MVC 主動 被動 1. 顯示出所要開啟的網頁 2. 使用者登入驗證 1 2 3. 內部資料的存取 3
  • 5. ASP.NET MVC • View – HTML/XML/CSS – JSON – Javascript (jQuey, JQuery UI, Ext JS,…) – AJAX • Control – ASP.NET Controller • Model – ADO.NET – Entity Framework – LINQ to SQL – Database operation
  • 6. ASP.NET MVC & Web Form Web Form • 優點 – 快速開發 (viewstate) – 不用了解HTML & CSS • 缺點 – 控制元件不易微調 – 不容易測試 MVC • 優點 – 簡化複雜度 – 易於分工 – 更容易測試 – 採用同一套開發習慣 • 缺點 – 缺乏元件支援
  • 7. ASP.NET MVC & Web Form Web Form • View based • Design Flow – 建立”Order”資料夾 – 建立”addorder.aspx” – 從工具列拉UI元件 – 連接到datasource • Example Code – File structure – About – Register/login MVC • Controller based • Design Flow – URL配置 – Controller對應 – 取得對應的Model – 將model的資料傳到view – 實作view • Example Code – File structure – About – Register/login
  • 8. 系統開發流程 1. 網站規劃 – 網站規畫 – 網站功能 – 資料模型規畫 2. 建立Model 3. 建立Controller 4. 調整View
  • 9. 範例實作 – 網站規劃 • 建立一個可以新增、修改、刪除SNMP設備 的網頁 • 資料庫設計 索引 名稱 資料型別 允許空值 範圍 Key Index int DeviceName nvarchar(32) DeviceIP varhar(32) SNMPVersion int 1 ~ 2 ReadCommunity varchar(32) WriteCommunity varchar(32) DeviceType int ● DeviceStatus int ●
  • 10. 範例實作 – 建立Model • 選Models-> 右鍵 -> 加入 -> 類別
  • 11. 範例實作 – 建立Model • DeviceInfo.cs – 程式碼優先開發模式 (Code First) – using System.ComponentModel; – using System.ComponentModel.DataAnnotations; • [Key]:索引 • [Required]:可否為null • [DisplayName(“設備名稱”)]:View上面所看到的名稱 • [MaxLength(32)]:最大的字串長度 • [Range(1, 2)]:數值的範圍
  • 12. 範例實作 – 建立Controller • 選”Controller” ->右鍵 -> 加入 -> 控制器
  • 13. 範例實作 – 調整View • 將DeviceType與DeviceStatus的欄位隱藏起來
  • 14. 程式說明 • 如何看到Model存放的資料 • RouteConfig.cs • DeviceInfoController.cs • Index.cshtml • Create.cshtml