ASP.NET MVC Best Practices 27+

來源:互聯網
上載者:User

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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.