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

目录
相关文章
|
3月前
|
开发框架 前端开发 .NET
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
42 0
|
1月前
|
开发框架 前端开发 .NET
进入ASP .net mvc的世界
进入ASP .net mvc的世界
29 0
|
1月前
mvc.net分页查询案例——mvc-paper.css
mvc.net分页查询案例——mvc-paper.css
5 0
|
1月前
|
开发框架 前端开发 .NET
C# .NET面试系列六:ASP.NET MVC
<h2>ASP.NET MVC #### 1. MVC 中的 TempData\ViewBag\ViewData 区别? 在ASP.NET MVC中,TempData、ViewBag 和 ViewData 都是用于在控制器和视图之间传递数据的机制,但它们有一些区别。 <b>TempData:</b> 1、生命周期 ```c# TempData 的生命周期是短暂的,数据只在当前请求和下一次请求之间有效。一旦数据被读取,它就会被标记为已读,下一次请求时就会被清除。 ``` 2、用途 ```c# 主要用于在两个动作之间传递数据,例如在一个动作中设置 TempData,然后在重定向到另
100 5
|
3月前
|
XML 前端开发 定位技术
C#(NET Core3.1 MVC)生成站点地图(sitemap.xml)
C#(NET Core3.1 MVC)生成站点地图(sitemap.xml)
25 0
|
3月前
|
前端开发
.net core mvc获取IP地址和IP所在地(其实是百度的)
.net core mvc获取IP地址和IP所在地(其实是百度的)
124 0
|
5月前
|
开发框架 自然语言处理 前端开发
基于ASP.NET MVC开发的、开源的个人博客系统
基于ASP.NET MVC开发的、开源的个人博客系统
52 0
|
8月前
|
SQL 开发框架 前端开发
[回馈]ASP.NET Core MVC开发实战之商城系统(完:内附源码)
经过一段时间的准备,【ASP.NET Core MVC开发实战之商城系统】已经完成,目前代码已开发完成,先将全部内容整理分享,如有不足之处,还请指正。
107 0
|
8月前
|
存储 开发框架 前端开发
[回馈]ASP.NET Core MVC开发实战之商城系统(五)
经过一段时间的准备,新的一期【ASP.NET Core MVC开发实战之商城系统】已经开始,在之前的文章中,讲解了商城系统的整体功能设计,页面布局设计,环境搭建,系统配置,及首页【商品类型,banner条,友情链接,降价促销,新品爆款】,商品列表页面,商品详情等功能的开发,今天继续讲解购物车功能开发,仅供学习分享使用,如有不足之处,还请指正。
117 0
|
9月前
|
开发框架 前端开发 .NET
[回馈]ASP.NET Core MVC开发实战之商城系统(三)
[回馈]ASP.NET Core MVC开发实战之商城系统(三)
67 0