\t\tAsp.net MVC VS Asp.net WebForms

最近学习了Asp.net MVC,感觉到了一种新颖的开发模式,和WebFroms开发有很大的不同。那么我们应该怎样的看待这两种开发模式呢?以及我们应该怎么进行取舍?

一、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.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值