ASP.NET MVC 入门介绍【翻译】
Introduction to ASP.NET MVC
Author : Shailendra Chauhan
Posted On : 15 Jun 2011
Total Views : 135,825
Updated On : 13 Aug 2015
ASP.NET MVC is a new web application framework from Microsoft. MVC stands for Model-View-Controller, a pattern that’s becoming increasingly popular with web development frameworks. ASP.NET MVC is an alternative and a complement to Web Forms, which means you won’t be dealing with pages and controls, postbacks or view state, or complicated ASP.NET event life cycle.
ASP.NET MVC是一个来自微软的新的web应用程序框架。MVC代表模型-视图-控制器,这种模式在web开发框架中越来越流行。ASP.NET MVC是Web Forms的另一种替代和补充,这意味着您不需要处理页面和控件、postbacks、view state或复杂的ASP.net 事件生命周期
Basically, MVC is a framework methodology that divides an application's implementation into three component roles: models, views, and controllers. Hence in Asp.net MVC you need to play with controllers, actions, and views.
基本上,MVC是一种框架方法,它将应用程序的实现划分为三个组件:模型、视图和控制器。因此在Asp.net MVC中你需要使用控制器,动作和视图
MVC Pattern
The Model-View-Controller (MVC) pattern is an adaptation of a pattern generated from the Smalltalk community in the 1970s by Trygve Reenskaug. It was popularized for use on the web with the advent of Ruby on Rails in 2003.
模型-视图-控制器(MVC)模式是由Trygve Reenskaug在上世纪70年代由Smalltalk社区产生的模式的改编。它在2003年随着Ruby on Rails的出现而在网络上流行起来
- 1. Model
Models in a MVC based application are the components of the application that are responsible for maintaining state. Often this state is persisted inside a database for example: we might have a Product class that is used to represent order data from the Products table inside SQL.
在基于MVC的应用程序中,模型是负责维护状态的应用程序的组件。通常,这种状态会持久化到数据库中,例如:我们可能有一个产品类,用于表示SQL中产品表中的订单数据
- 2. View
Views in a MVC based application are the components responsible for displaying the application's user interface. Typically this UI is created off of the model data for example: we might create an Product "Edit" view that surfaces textboxes, dropdowns and checkboxes based on the current state of a Product object.
基于MVC的应用程序中的视图是负责显示应用程序用户界面的组件。典型的UI是由模型数据创建的例如:我们可能创建一个产品“编辑”视图,它根据产品对象的当前状态来显示文本框、下拉框和复选框
- 3. Controller
Controllers in a MVC based application are the components
responsible for handling end user interaction, manipulating the model, and
ultimately choosing a view to render to display UI. In a MVC application the
view is only about displaying information - it is the controller that handles
and responds to user input and interaction.
基于MVC的应用程序中的控制器是负责处理最终用户交互的组件,操纵模型,并最终选择一个视图来显示UI。在MVC应用程序中,视图仅用于显示信息——它是处理和响应用户输入和交互的控制器
ASP.NET MVC Web Application Advantages优势
The ASP.NET MVC Framework is a new framework and have the following advantages over Web Forms approach (means over ASP.Net):
ASP.NET MVC框架是一个新的框架,它比Web Forms方法更有优势(意味着超越ASP.Net)
- 1. Separation of concern 概念分离
In ASP.NET MVC the application is divided to Model, View
and Controller parts which make it easier to manage the application complexity.
在ASP.NET MVC应用程序被划分为模型、视图和控制器部分,这使得管理应用程序的复杂性变得更加容易
- 2. TDD 测试驱动开发
The ASP.NET MVC framework brings better support to
test-driven development.
ASP.NET MVC框架为测试驱动开发提供了更好的支持
- 3. Extensible and pluggable 可扩展和可拔插式
ASP.NET MVC framework components were designed to be
pluggable and extensible and therefore can be replaced or customized easier
then Web Forms.
ASP.NET MVC框架组件被设计成可插拔和可扩展的,因此可以替换或轻松定制Web Forms
- 4.
Full control over
application behavior
对应用程序行为的完全控制
ASP.NET MVC framework doesn’t use View State or server
based forms like Web Forms. This gives the application developer more control
over the behaviors of the application and also reduces the bandwidth of
requests to the server.
ASP.NET MVC框架不使用像Web forms那样的视图状态或基于服务器的表单。这样,应用程序开发人员就可以对应用程序的行为进行更多的控制,并减少对服务器的请求的带宽
- 5.
ASP.NET features
are supported
ASP.NET 特性支持
ASP.NET MVC framework is built on top of ASP.NET and therefore can use most of the features that ASP.NET include such as the providers architecture, authentication and authorization scenarios, membership and roles, caching, session and more.
ASP.NET MVC框架是建立在ASP.NET之上的。因此可以使用ASP.NET的大部分特性。包括提供者体系结构、身份验证和授权场景、成员身份和角色、缓存、会话等等
- 6.
URL routing
mechanism
URL路由机制
ASP.NET MVC framework supports a powerful URL routing
mechanism that helps to build a more comprehensible and searchable URLs in your
application. This mechanism helps to the application to be more addressable
from the eyes of search engines and clients and can help in search engine
optimization.
ASP.NET MVC框架支持强大的URL路由机制,帮助您在应用程序中构建更易于理解和可搜索的URL。这种机制可以帮助应用程序从搜索引擎和客户的眼睛中获得更大的可寻址,并且可以帮助搜索引擎优化
The ASP.NET MVC simplifies the complex parts of ASP.net Web Forms without
any compromise of the power and flexibility of ASP.NET platform. ASP.net MVC
implements Model-View-Controller UI pattern for web application development
that lets you allows to develop applications in a loosely couples manner. MVC
pattern is separating the application in three parts- Model, View and
Controller.
ASP.NET MVC简化了ASP.net Web表单的复杂部分,而没有对ASP.NET的强大和灵活性做出任何妥协。ASP.NET MVC实现了用于web应用程序开发的模型-视图-控制器UI模式,允许您以一种松散的方式开发应用程序。MVC模式将应用程序分为三个部分:模型、视图和控制器