一、Asp.net MVC是什么?
Asp.net MVC是一个基于微软发布的MVC的框架,目的和Webforms是一样的,可以高效快速的开发Web应用程序。那它和webforms有什么冲突呢?用Microsoft来话来说,Asp.net MVC并不是Webforms的替换,也不是互补,要么用Asp.net MVC,要么用Asp.net WebForms。但在某些场景下asp.net MVC比asp.net Webform要更有优势,但是在另外一些情况下:asp.net webform要更适合一些。
二、Asp.net MVC产生
在Asp.net MVC出现之前,已经有很多MVC框架,很多开发人员觉得MVC框架更适合做Web开发。而且很多的asp.net开发人员都不愿意使用服务器控件。所以微软决定自己开发一套属于自己的MVC框架。
三、Asp.net WebForms特点
优点:拖控件,和window form一样,快速,高效的开发。
缺点:
1.服务器控件自动的产生自己相关的HTML的代码,在一定的程度上是控制不了,而且很容易发生命名冲突。
2.ViewState是Client和Server保存视图状态的一种方式,但是影响性能,而且当ViewState太大的时候,会引起错误。
3.自动生成的ID是不可控制的。所以用Javascript增加它的行为很困难。
4.对单元测试支持不好。
四、Asp.net MVC Framework
优点:
1.Clear separation of concerns
2.Testability-support for Test-Dirven Development
3.Fine-grained control over HTML and Javascript
4.Intuitive URLs(友好的URL)
5.Extensible to adapt to you unique needs(扩展能力强)
缺点:
1.Require developers to have more html,css and javascript knowledge.
2.write more code,both server-side and client-side
(1)Controlller(with Action,Action Result)
Controllers process incoming request,handle user input and interactions,and excute appropriate application logic.A controller class typically calls a
separate view component to generate the HTML markup for the request.
User interaction with Asp.net MVC application is organized around controller and action method.the controller defines action methods.
ActionResult is what an Action returns,it could be a view result,a redirect,etc.
(2)Model
Your business logic and your data access goes here.
(3)View
Aspx is used to render views.
View should not have any business logic
Controller passes to view the data required for rendering,no more,no less.
(4)URL Routing
URLRoutingModule is the responsible for URL routings.
URL routing is based on patterns
(5)Helpers
Helpers are basically objects to help us generate code,be it HTML,CSS,Javascript.
Helpers are mainly used to help us type less code.
HTML.ActionLink(...)
(6)Action Filters
A way to intercept action method calls,works like AOP.
Server build-in action filters are provided by default.
you can create your own very easily
Sample:Authorize OutputCache
(7)Model Binding
It's a way of structuring input data,rather than reading all input data from the Request object collection.
(8)Form Validation
You can error message related to model throuth the viewData.Modelstatus
you output these message with the HTML Helper mothod HTML.ValidationMessage.