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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值