2010年9月26日

Best Practices for ASP.NET MVC

這是微軟 msdn 上的一篇文章,分別就 model, view, controller, routing, extensibility, testability, security, localization and globalization, performance, 建議應採取的設計方式。內容對於 mode, view, controller 的分工方式, 有很好的說明, 相信對於採用 MVC 的設計師, 會有很大的幫助。

以下,我簡單列出一些要點:

Model: 用來定義商業、資料、驗證與記錄使用者狀態 session 等邏輯,對於大型的系統,可以拆成不同的 assembly。

View: 不要把商業邏輯寫在 View 中,要有可讀性。可以利用 partial HTML view(.ascx)來建立階層結構。要利用 ViewData 方式讀取資料,以 server 端註解 <%-- --%>增加安全性,採用 HTML Helper 產生 form、checkbox、textbox..。

Controller: 針對 routing system、HTML resuest 來回應。使用 model binding 取代手動,以 Post/Redirect/Get 處理 submitting form。並要記得管理 HandleUnknownAction 與 HandleError等狀況。

[Reference]
Best Practices for ASP.NET MVC

沒有留言:

Deploying Vue & .NET with Google OAuth on GCP Cloud Run

Deploying Vue & .NET with Google OAuth on GCP Cloud Run Deploying Vue & .NET with Google OAuth on GCP Cloud Run...