ASP.NET MVC Best Practices 27+

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 

best1 

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

best2

原文地址:

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