ASP.NET MVC Best Practices 27+
2009-11-11 20:08
525 查看
12 ASP.NET MVC Best Practices
M
DomainModel != ViewModel
Use ActionFilters for “shared” data
V
Do NEVER user code-behind
Write HTML each time you can
If there is an if, write an HtmlHelper
Choose your view engine carefully
C
Delete the AccountController
Isolate Controllers from the outside World
Use an IoC Container
Say NO to “magic strings”
Build your own “personal conventions”
Pay attention to the Verbs
ASP.NET MVC Best Practices
Use
Use jQuery and jQuery UI
Use Bootstrapper in Global.asax
Use Action Filter to Convert to compatible Action Methods parameters
Use UpdateModel Carefully
Use PRG Pattern for Data Modification
Do Not
Do not make any hard dependency on the DI Container, use Common Service Locator
Do not put your JavaScript codes in your View
Avoid ViewData, use ViewData.Model
Do not make any hard dependency on the DI Container, use Common Service Locator
Controller will not contain any Domain logic
Decorate
Decorate your most frequent Action Methods with OutputCache Attribute
Decorate your Action Methods with Proper AcceptVerbs Attribute
Decorate your most frequent Action Methods with OutputCache Attribute
Decorate your Action Methods with Proper AcceptVerbs Attribute
Create
Create new ActionResult if required
Create Extension methods of UrlHelper to generate your url from Route
Create Layer Super Type for your ViewModel and Use Action Filter to populate common parts.
Create Extension Method of UrlHelper to map your JavaScript, Stylesheet and Image Folder
HtmlHelper extension
Split your View into multiple ViewUserControl
Tips
Routing consideration
Encode
Action Filter Location
Keep your controller free from HttpContext and its tail
原文地址:
http://weblogs.asp.net/rashid/archive/2009/04/01/asp-net-mvc-best-practices-part-1.aspx
http://codeclimber.net.nz/archive/2009/10/27/12-asp.net-mvc-best-practices.aspx
M
DomainModel != ViewModel
Use ActionFilters for “shared” data
V
Do NEVER user code-behind
Write HTML each time you can
If there is an if, write an HtmlHelper
Choose your view engine carefully
C
Delete the AccountController
Isolate Controllers from the outside World
Use an IoC Container
Say NO to “magic strings”
Build your own “personal conventions”
Pay attention to the Verbs
ASP.NET MVC Best Practices
Use
Use jQuery and jQuery UI
Use Bootstrapper in Global.asax
Use Action Filter to Convert to compatible Action Methods parameters
Use UpdateModel Carefully
Use PRG Pattern for Data Modification
Do Not
Do not make any hard dependency on the DI Container, use Common Service Locator
Do not put your JavaScript codes in your View
Avoid ViewData, use ViewData.Model
Do not make any hard dependency on the DI Container, use Common Service Locator
Controller will not contain any Domain logic
Decorate
Decorate your most frequent Action Methods with OutputCache Attribute
Decorate your Action Methods with Proper AcceptVerbs Attribute
Decorate your most frequent Action Methods with OutputCache Attribute
Decorate your Action Methods with Proper AcceptVerbs Attribute
Create
Create new ActionResult if required
Create Extension methods of UrlHelper to generate your url from Route
Create Layer Super Type for your ViewModel and Use Action Filter to populate common parts.
Create Extension Method of UrlHelper to map your JavaScript, Stylesheet and Image Folder
HtmlHelper extension
Split your View into multiple ViewUserControl
Tips
Routing consideration
Encode
Action Filter Location
Keep your controller free from HttpContext and its tail
原文地址:
http://weblogs.asp.net/rashid/archive/2009/04/01/asp-net-mvc-best-practices-part-1.aspx
http://codeclimber.net.nz/archive/2009/10/27/12-asp.net-mvc-best-practices.aspx
相关文章推荐
- ASP.NET MVC Best Practices 27+
- ASP.NET MVC Best Practices 27+
- AngularJS Best Practices: ASP.NET MVC Directory Structure
- ASP.NET MVC Code and Slides for Best of Mix 09 Presentation
- NHibernate Best Practices with ASP.NET, 1.2nd Ed(转).
- 推荐一篇好文《NHibernate Best Practices with ASP.NET and Generics》
- ASP.NET MVC Code and Slides for Best of Mix 09 Presentation
- NHibernate Best Practices with ASP.NET, 1.2nd Ed (4.1) NHibernate基本整合-架构备注
- NHibernate Best Practices with ASP.NET, 1.2nd Ed. from CodeProject.com
- ASP.NET MVC中的依赖倒置IOC/依赖注入DI, (MircroSoft.Practices.Unity)与asp.net mvc 3的融合
- [Reference]NHibernate Best Practices with ASP.NET, 1.2nd Ed.
- ASP.NET AJAX Best Practices: Careful with DOM element concatenation
- 【引】How to Choose the Best Way to Pass Multiple Models in ASP.NET MVC
- How to Choose the Best Way to Pass Multiple Models in ASP.NET MVC
- ASP.NET Solutions - 23 Case Studies: Best Practices for Developers by Rick Leinecker
- NHibernate Best Practices with ASP.NET, 1.2nd Ed (1) 序言
- NHibernate Best Practices with ASP.NET, 1.2nd Ed (2) 介绍
- 第二讲 Best Practices For Running IIS 6.0 And ASP.NET
- 返璞归真 asp.net mvc (3) - Controller/Action
- Spring.Net+NHibernate+Asp.Net mvc+ExtJs构建多层应用程序