四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

[一步一步MVC]第六回:什么是MVC(上)?

系列文章導(dǎo)航:

[一步一步MVC]第一回:使用ActionSelector控制Action的選擇

[一步一步MVC]第二回:還是ActionFilter,實(shí)現(xiàn)對(duì)業(yè)務(wù)邏輯的統(tǒng)一Authorize處理

[一步一步MVC]第三回:MVC范例大觀園

[一步一步MVC]第四回:漫談ActionLink,有時(shí)“胡攪蠻纏”

[一步一步MVC]第五回:讓TagBuilder豐富你的HtmlHelper

[一步一步MVC]第六回:什么是MVC(上)?


引言

所謂MVC,其實(shí)就是M、V、C而已。歸根揭底,MVC是一種表現(xiàn)模式,是一種軟件架構(gòu)模式。其中有幾個(gè)重要的概念:

  • M,Model, 引用系統(tǒng)數(shù)據(jù),管理系統(tǒng)功能并通知View更改用戶操作。
  • V,View,就是用戶接口,用于顯示數(shù)據(jù)。
  • C,Controller ,將用戶操作映射到Model,并操作視圖。
  • R,Routing ,MVC的奧秘在于通過(guò)Routing實(shí)現(xiàn)了對(duì)URL的路由選擇,完成了上述3個(gè)基本概念的基礎(chǔ)邏輯。

我們先來(lái)了解這幾個(gè)概念之間的聯(lián)系。

 

o_anytao-mvc-09-01[1]

對(duì)MVC而言,分離是最大的優(yōu)點(diǎn),尤其是Model將不依賴于Controller和View,對(duì)于隔離應(yīng)用、進(jìn)行UI測(cè)試打下很好的架構(gòu)級(jí)支持。

MVC Execution Process

關(guān)于MVC的執(zhí)行過(guò)程,我們就不多言了,從MSDN獲取的執(zhí)行過(guò)程可以被解析為:

o_anytao-mvc-09-02[1] 

在MVC模式下,不同于WebForm時(shí)代,業(yè)務(wù)邏輯的處理和HTML的輸出不是View(或Page)一個(gè)人的事兒,這些邏輯被清晰的分解為M、V和C的邏輯,具體的執(zhí)行流程為:

ASP.NET MVC Execution Process

Stage

Details

Receive first request for the application

In the Global.asax file, Route objects are added to the RouteTable object.

void Application_Start(object sender, EventArgs e) {    RegisterRoutes(RouteTable.Routes);}public static void RegisterRoutes(RouteCollection routes){    routes.Add(new Route    (         "Category/{action}/{categoryName}"         , new CategoryRouteHandler()    ));}

Perform routing

The UrlRoutingModule module uses the first matching Route object in the RouteTable collection to create the RouteData object, which it then uses to create a RequestContext object.

 

Create MVC request handler

The MvcRouteHandler object creates an instance of the MvcHandler class and passes the RequestContext instance to the handler.

Create controller

The MvcHandler object uses the RequestContext instance to identify the IControllerFactory object (typically an instance of the DefaultControllerFactory class) to create the controller instance with.

Execute controller

The MvcHandler instance calls the controller's Execute method.

Invoke action

For controllers that inherit from the ControllerBase class, the ControllerActionInvoker object that is associated with the controller determines which action method of the controller class to call, and then calls that method.

Execute result

The action method receives user input, prepares the appropriate response data, and then executes the result by returning a result type. The built-in result types that can be executed include the following: ViewResult (which renders a view and is the most-often used result type), RedirectToRouteResult, RedirectResult, ContentResult, JsonResult, FileResult, and EmptyResult.

NET技術(shù)[一步一步MVC]第六回:什么是MVC(上)?,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 小敏的迦南诗歌大全| 美女下面流水| 夜魔3| 柏拉图的电影| 搜狐手机首页| 永远的经典影片永远的| 恶魔实验豚鼠| 最可爱的人 电影| 猪哥会社| 赵汉善| 复仇者联盟4免费完整版电影| 全国精神病查询系统官网| 冬日舞蹈教程完整版| 漫画启示作文五年级| 音乐僵尸演员表| 成龙版杨家将电影免费播放| 港股三大指数| 张念骅| 美女写真裸体| 在人间在线观看完整版| 他其实没那么爱你电影| 晕车喝什么饮料能缓解| 夜生活女王之霞姐| 富二代| 自拍在线播放| 乔什布洛林| 保镖电影大全免费| 情欲狂欢h版| 电影理发师| 林正英僵尸先生电影在线观看| 军官与男孩| 电影《年龄差》| 湖南金鹰卡通节目表| 围城电影| 疯狂 电影| 陕西卫视节目表| 小丑回魂1| 欧布奥特曼普通话| 不可饶恕 电影| 大胆艺术| 扎职|