對於Microsoft平臺上的Web開發人員來講,使用ASP.NET Core MVC是一次完全的轉變。它強調整潔的架構,設計模式和可測試性,而且不會試圖隱藏Web的工做方式。 前端
ASP.NET Core MVC is a radical shift for web developers using the Microsoft platform. It emphasizes clean architecture, design patterns, and testability, and it doesn’t try to conceal how the Web works. git
本書的第一部分旨在幫助你普遍理解MVC開發,包括 ASP.NET Core MVC中的新功能,以及在實踐中體驗框架的使用方式。程序員
The first part of this book is designed to help you understand broadly the foundational ideas of MVC development, including the new features in ASP.NET Core MVC, and to experience in practice what the framework is like to use.github
ASP.NET Core MVC是一個來自Microsoft的Web應用程序開發框架,它結合了 」模型/視圖/控制器「(MVC)體系結構的有效性和整潔性、敏捷開發的觀念以及.NET平臺的最佳部分。本章將介紹Microsoft建立ASP.NET Core MVC的緣由、它與其前身、競爭框架的比較,以及在ASP.NET Core MVC中的新增的內容。web
ASP.NET Core MVC is a web application development framework from Microsoft that combines the effectiveness and tidiness of model-view-controller (MVC) architecture, ideas and techniques from agile development, and the best parts of the .NET platform. In this chapter, you’ll learn why Microsoft created ASP.NET Core MVC, see how it compares to its predecessors and alternatives, and, finally, get an overview of what’s new in ASP.NET Core MVC and what’s covered in this book.數據庫
2002年,微軟推出了初代ASP.NET,當時,微軟熱衷於保護傳統桌面應用程序開發的主導地位,並將互聯網的蓬勃發展視爲威脅。 當時微軟的技術棧以下圖所示所示:express
The original ASP.NET was introduced in 2002, at a time when Microsoft was keen to protect a dominant position in traditional desktop application development and saw the Internet as a threat. Figure 1-1 illustrates Microsoft’s technology stack as it appeared then.編程
在Web Forms中,Microsoft試圖經過將UI建模爲具備層次結構的服務器端對象,來隱藏無狀態的HTTP以及當時許多開發人員並不熟悉的HTML。每一個控件都會追蹤各個請求的狀態,在須要時將其渲染爲HTML,並自動地將客戶端事件(好比點擊按鈕)與相應的服務器端事件處理代碼鏈接起來。實際上,Web Forms是一個旨在於在Web上也提供傳統的事件驅動型GUI的巨大抽象層。設計模式
With Web Forms, Microsoft attempted to hide both Hypertext Transfer Protocol (HTTP), with its intrinsic statelessness, and Hypertext Markup Language (HTML), which at the time was unfamiliar to many developers, by modeling the user interface (UI) as a hierarchy of server-side control objects. Each control kept track of its own state across requests, rendering itself as HTML when needed and automatically connecting client-side events (for example, a button click) with the corresponding server-side event handler code. In effect, Web Forms is a giant abstraction layer designed to deliver a classic event-driven graphical user interface (GUI) over the Web.promise
這種作法試圖讓開發人員在Web上也能擁有開發桌面應用通常的體驗。開發人員能夠基於有狀態的UI進行思考,而不須要處理一系列獨立的HTTP請求和響應。所以,微軟能夠無縫地使Windows桌面開發人員轉變成Web應用開發人員。
The idea was to make web development feel just the same as developing a desktop application. Developers could think in terms of a stateful UI and didn’t need to work with a series of independent HTTP requests and responses. Microsoft could seamlessly transition the army of Windows desktop developers into the new world of web applications.
原則上來講,ASP.NET Web Forms並不壞,但現實卻沒有這麼簡單。
Traditional ASP.NET Web Forms development was good in principle, but reality proved more complicated.
雖然Web Forms很爛,但它也並非一無可取,而且最後微軟致力於改進標準合規性,並簡化開發流程。微軟甚至從原始的ASP.NET MVC框架中汲取了一些功能,並將它們應用到Web Forms中去。當須要一個快速的開發結果時,Web Forms表現出色,而且在一天內就能寫完並運行一個至關複雜的Web應用。可是,除非在開發過程當中足夠當心,不然你會發現你寫出來的東西很難測試也很難維護。
Web Forms wasn’t all bad, and eventually, Microsoft put effort into improving standards compliance and simplifying the development process and even took some features from the original ASP.NET MVC Framework and applied them to Web Forms. Web Forms excelled when you needed quick results, and you could have a reasonably complex web app up and running within a day. But unless you were careful during development, you would find that the application you created was hard to test and hard to maintain.
2007年10月,微軟發佈了一個基於現有ASP.NET平臺的新開發平臺,旨在於直接回應對Web Forms的批評和Ruby on Rails等競爭平臺的普及。這個新平臺被稱爲ASP.NET MVC,它反映了Web應用程序開發中的新興趨勢,如HTML和CSS標準化、RESTful的Web服務、有效的單元測試以及開發人員應該接受HTTP的無狀態特性的想法。
In October 2007, Microsoft announced a new development platform, built on the existing ASP.NET platform, that was intended as a direct response to the criticisms of Web Forms and the popularity of competing platforms such as Ruby on Rails. The new platform was called the ASP.NET MVC Framework and reflected the emerging trends in web application development, such as HTML and CSS standardization, RESTful web services, effective unit testing, and the idea that developers should embrace the stateless nature of HTTP.
這些支撐着原始MVC框架的概念,在如今看起來是很天然的,可是在2007年的.NET Web開發領域,它卻並不爲人所知。ASP.NET MVC框架的引入使得微軟從新再Web開發平臺跟上時代。
The concepts that underpin the original MVC Framework seem natural and obvious now, but they were lacking from the world of .NET web development in 2007. The introduction of the ASP.NET MVC Framework brought Microsoft’s web development platform back into the modern age.
MVC框架的發佈標誌着微軟的態度發生了重大變化。此前,微軟試圖控制Web應用程序工具鏈中的每一個組件。藉助MVC框架,Microsoft引入諸如jQuery之類的開源工具,從更成功的競爭的平臺上接受了設計慣例和最佳實踐,並將源代碼發佈到MVC框架中供開發人員進行檢查。
The MVC Framework also signaled an important change in attitude from Microsoft, which had previously tried to control every component in the web application toolchain. With the MVC Framework, Microsoft built on open source tools such as jQuery, took on design conventions and best practices from competing (and more successful) platforms, and released the source code to the MVC Framework for developers to inspect.
當時,在ASP.NET平臺已經有了不少可靠的底層功能,而且也已經爲開發人員所熟知。對於微軟而言,在此之上建立一個高層的MVC框架是頗有意義的。
At the time the MVC Framework was created, it made sense for Microsoft to create it on top of the existing ASP.NET platform, which had a lot of solid low-level functionality that provided a head start in the development process and which was already well-known and understood by ASP.NET developers.
可是,爲了將MVC嫁接到最初僅爲Web Forms設計的平臺上,開發人員須要付出很大努力和妥協。爲了讓網站正常工做,MVC框架開發人員變得習慣於經過不停調整配置文件或代碼來完成一些功能的配置,哪怕這些對於業務來講,並無任何直接影響。
But compromises were required to graft the MVC Framework onto a platform that was originally designed for Web Forms. MVC Framework developers became used to using configuration settings and code tweaks that disabled or reconfigured features that didn’t have any bearing on their web application but were required to get everything working.
隨着MVC框架變得愈來愈流行,微軟開始將其一部分核心功能添加到Web Forms中。結果是一切變得愈來愈奇怪。一些怪癖的MVC框架設計擴展到Web窗體,使得全部的奇怪的東西都融合在了一塊兒。與此同時,微軟開始使用新的框架來擴展ASP.NET,好比建立Web服務的Web API和支持實時通訊的SignalR。新的框架增長了他們本身的配置和約定,且每一個框架都有本身的長處和怪異之處,整體結果來看,就是一團糟。
As the MVC Framework grew in popularity, Microsoft started to take some of the core features and add them to Web Forms. The result was increasingly odd, where features with design quirks required to support the MVC Framework were extended to support Web Forms, with further design quirks to make everything fit together. At the same time, Microsoft started to expand ASP.NET with new frameworks for creating web services (Web API) and real-time communication (SignalR). The new frameworks added their own configuration and development conventions, each of which had its own benefits and oddities, and the overall result was a fragmented mess.
2015年,微軟宣佈了ASP.NET和MVC框架的新方向,最終造成了本書的主題 —— ASP.NET Core MVC。
In 2015, Microsoft announced a new direction for ASP.NET and the MVC Framework, which would eventually produce ASP.NET Core MVC, the topic of this book.
ASP.NET Core創建在.NET Core之上。它是.NET Framework的跨平臺版本,不包含任何Windows平臺特定的API。目前,雖然Windows仍然是市場上占主導地位的操做系統,可是Web應用程序愈來愈多地被託管在雲平臺中的小而輕的容器中。經過跨平臺的方法,微軟擴展了.NET的範圍,使得將ASP.NEY Core部署在更普遍的環境中成爲可能,而且開發人員甚至能夠在Linux和MacOS上建立ASP.NET Core Web應用程序。
ASP.NET Core is built on .NET Core, which is a cross-platform version of the .NET Framework without the Windows-specific application programming interfaces (APIs). Windows is still a dominant operating system, but web applications are increasingly hosted in small and simple containers in cloud platforms, and by embracing a cross-platform approach, Microsoft has extended the reach of .NET, made it possible to deploy ASP.NET Core applications to a broader set of hosting environments, and, as a bonus, made it possible for developers to create ASP.NET Core web applications on Linux and macOS.
ASP.NET Core是一個全新的框架。它更簡單,易於使用,而且甩掉了來自Web Forms的歷史遺留問題。並且,它基於.NET Core,所以支持在各類平臺和容器上開發Web應用程序和部署。
ASP.NET Core is a completely new framework. It is simpler, it is easier to work with, and it is free of the legacy that comes from Web Forms. And, since it is based on .NET Core, it supports the development of web applications on a range of platforms and containers.
ASP.NET Core MVC提供了在新的ASP.NET Core平臺上構建ASP.NET MVC Framework的功能。 它集成了以前由Web API提供的功能,使用了一種更天然的方式來生成複雜的內容,並使得單元測試等重要的開發任務變得更簡單和可預測。
ASP.NET Core MVC provides the functionality of the original ASP.NET MVC Framework built on the new ASP.NET Core platform. It integrates the features that were previously provided by Web API, it includes a more natural way of generating complex content, and it makes key development tasks, such as unit testing, simpler and more predictable.
ASP.NET Core MVC 2的重點關注是功能的鞏固和整合,更好地協同在其早期版本中引入的工具和平臺進行工做。ASP.NET Core MVC 2須要.NET Core 2的支持,.NET Core 2具備不少擴展的API,而且受Linux發行版的支持。有用的更改還包括一簡化了的NuGet包管理系統,一個新的ASP.NET Core配置系統,和對Entity Framework Core 2的支持。最大的新功能是Razor Pages,這是一個使用更具現代化開發風格的,對Web頁面進行重建的嘗試。但對MVC開發人員對Razor Pages可能並不感興趣(我在本書中也沒有描述它)。
The ASP.NET Core MVC 2 release focuses on consolidation, working through some of the tooling and platform changes that were introduced in earlier versions. ASP.NET Core MVC 2 requires .NET Core 2, which has a much-expanded API surface and is now supported on additional Linux distributions. Useful changes include a new meta-package system, which simplifies the management of NuGet packages, a new configuration system for ASP.NET Core, and support for Entity Framework Core 2. The biggest new feature is Razor Pages, which is an attempt to re-create the development style associated with Web Pages using a more modern platform, but Razor Pages will not be of interest for MVC developers (and I do not describe it in this book).
如下部分將簡要介紹新的MVC平臺是如何克服Web Forms和原始MVC框架的遺留問題,以及如何將ASP.NET帶回潮流最前端的。
The following sections briefly describe how the new MVC platform overcomes the legacy of Web Forms and the original MVC Framework and how it has brought ASP.NET back to the cutting edge.
ASP.NET Core MVC遵循一種稱爲模型/視圖/控制器(model-view-controller)的模式,它指定了ASP.NET Web應用程序的形態以及它所包含的組件之間的交互方式。
ASP.NET Core MVC follows a pattern called model-view-controller, which guides the shape of an ASP.NET web application and the interactions between the components it contains.
區分MVC體系結構模式和ASP.NET Core MVC的具體實現是很重要的。MVC模式並非什麼新鮮玩意兒,它能夠追溯到1978年的Xerox PARC的Smalltalk項目。可是,因爲如下緣由,它如今做爲一種Web應用程序的模式更受歡迎:
It is important to distinguish between the MVC architectural pattern and the ASP.NET Core MVC implementation. The MVC pattern is not new—it dates back to 1978 and the Smalltalk project at Xerox PARC—but it has gained popularity today as a pattern for web applications for the following reasons:
ASP.NET Core MVC實現了MVC模式,與Web Forms相比,這種作法大大有助於實現關注點分離。事實上,ASP.NET Core MVC實現了一些特別適用於Web應用程序的MVC模式的變體。第3章將更多地介紹這種體系結構的理論和實踐。
ASP.NET Core MVC implements the MVC pattern and, in doing so, provides a greatly improved separation of concerns when compared to Web Forms. In fact, ASP.NET Core MVC implements a variant of the MVC pattern that is especially suitable for web applications. You will learn more about the theory and practice of this architecture in Chapter 3.
ASP.NET Core和ASP.NET Core MVC被構建爲一系列具備明肯定義的、實現了.NET接口或構建於抽象基類上的獨立組件。而且能夠輕鬆地使用自定義的實現來替換關鍵組件。通常來講,ASP.NET Core MVC爲每一個組件提供瞭如下三個選項:
ASP.NET Core and ASP.NET Core MVC are built as a series of independent components that have well-defined characteristics, satisfy a .NET interface, or are built on an abstract base class. You can easily replace key components with ones of your own implementation. In general, ASP.NET Core MVC gives you these three options for each component:
abstract base class.
第14章將介紹各類組件以及想替換他們的緣由以及具體方法。
You’ll learn all about the various components and how and why you might want to tweak or replace
each of them, starting in Chapter 14.
ASP.NET Core MVC會生成整潔的、符合標準的標籤。其內置的tag helper能夠生成符合標準的輸出。與Web Forms相比,其中有一個更重要的理念變化。ASP.NET Core MVC鼓勵用戶寫出更簡單、優雅的HTML和CSS,而不是生成大量沒法控制的HTML。
ASP.NET Core MVC produces clean, standards-compliant markup. Its built-in tag helpers produce standards-compliant output, but there is a more significant philosophical change compared with Web Forms. Instead of generating out swathes of HTML over which you have little control, ASP.NET Core MVC encourages you to craft simple, elegant markup styled with CSS.
固然,若是你想爲複雜的UI元素(如日期選擇器或級聯菜單)使用一些現成的小部件,那麼ASP.NET Core MVC中所採用的「無特殊要求」的方法就能夠輕鬆地使用這些最佳解決方案,包括jQuery、Angular、React或Bootstrap之類的客戶端庫。ASP.NET Core MVC與這些庫進行了良好的匹配,便於微軟包含它們的模板,以啓動新的開發項目。
Of course, if you do want to throw in some ready-made widgets for complex UI elements such as date pickers or cascading menus, the 「no special requirements」 approach taken by ASP.NET Core MVC makes it easy to use best-of-breed client-side libraries such as jQuery, Angular, React, or the Bootstrap CSS library. ASP.NET Core MVC meshes so well with these libraries that Microsoft includes templates that incorporate them to jump-start new development projects.
ASP.NET Core MVC與HTTP工做得十分協調順暢。能夠直接控制瀏覽器和服務器之間的請求傳遞,所以能夠儘量多地調整用戶的使用體驗。如第20章所述,Ajax通過了簡化,使得建立Web服務來接收瀏覽器HTTP請求成爲一件很簡單的事。
ASP.NET Core MVC works in tune with HTTP. You have control over the requests passing between the browser and server, so you can fine-tune your user experience as much as you like. Ajax is made easy, and creating web services to receive browser HTTP requests is a simple process, as described in Chapter 20.
ASP.NET Core MVC體系結構爲應用程序變得可維護和可測試提供了一個良好的開始,由於能夠天然地將不一樣的問題分解爲獨立的部分。此外,每一個ASP.NET Core平臺和ASP.NET Core MVC框架均可以被隔離並替換爲單元測試,這可使用任何流行的開源測試框架來執行,好比在第一章中將介紹的xUnit 7。
The ASP.NET Core MVC architecture gives you a great start in making your application maintainable and testable because you naturally separate different application concerns into independent pieces. In addition, each piece of the ASP.NET Core platform and the ASP.NET Core MVC framework can be isolated and replaced for unit testing, which can be performed using any popular open source testing framework, such as xUnit, which I introduce in Chapter 7.
在本書中,將介紹如何使用各類測試和模擬策略,來爲ASP.NET MVC控制器編寫乾淨、簡單的單元測試,以及提供框架組件的Mock實現來模擬任何場景。即便你之前從未寫過單元測試,這也是一個好的開始。
In this book, you will see examples of how to write clean, simple unit tests for ASP.NET MVC controllers and actions that supply fake or mock implementations of framework components to simulate any scenario, using a variety of testing and mocking strategies. Even if you have never written a unit test before, you will be off to a great start.
可測試性不只僅只是單元測試的問題。ASP.NET Core MVC應用程序也能夠與UI自動化測試工具一塊兒使用。能夠編寫模擬用戶交互的測試腳本,而不用去猜想框架將生成哪些HTML元素結構、CSS和ID,而且沒必要擔憂結構的意外更改。
Testability is not only a matter of unit testing. ASP.NET Core MVC applications work well with UI automation testing tools, too. You can write test scripts that simulate user interactions without needing to guess which HTML element structures, CSS classes, or IDs the framework will generate, and you do not have to worry about the structure changing unexpectedly.
統一資源定位符(URL)的風格隨着Web應用程序技術的改進而發展。這樣的網址:
/App_v2/User/Page.aspx?action=show%20prop&prop_id=82742
已經愈來愈少見,取而代之的是更簡單、更清晰的格式:
/to-rent/chicago/2303-silver-street
The style of uniform resource locators (URLs) has evolved as web application technology has improved. URLs like this one:
/App_v2/User/Page.aspx?action=show%20prop&prop_id=82742
are increasingly rare, replaced by a simpler, cleaner format like this:
/to-rent/chicago/2303-silver-street
關注URL的結構有一些很好的理由。首先,搜索引擎會對URL中的關鍵字進行加權。搜索「芝加哥租房」更容易出現更簡單的網址。其次,如今許多網絡用戶已經足夠了解URL,而且更願意直接在瀏覽器的地址欄中輸入地址的方式進行導航。第三,當有人瞭解URL的結構時,他們更有可能點它,並分享出去,甚至在電話中將其讀出來。第四,它不會將應用程序的技術細節,文件夾和文件名結構公開到互聯網上,所以能夠自由更改底層實現而不會中斷全部傳入連接。
There are some good reasons for caring about the structure of URLs. First, search engines give weight
to keywords found in a URL. A search for 「rent in Chicago」 is much more likely to turn up the simpler URL. Second, many web users are now savvy enough to understand a URL and appreciate the option of navigating by typing it into their browser’s address bar. Third, when someone understands the structure of a URL, they are more likely to link to it, share it with a friend, or even read it aloud over the phone. Fourth, it doesn’t expose the technical details, folder, and file name structure of your application to the public Internet, so you are free to change the underlying implementation without breaking all your incoming links.
整潔的URL在早期的框架中很難實現。但ASP.NET Core MVC使用一種稱爲URL路由的功能默認提供乾淨的URL。而且能夠經過控制URL模式與應用程序的對應關係替換默認模式,來自由建立對用戶有意義且有用的URL模式。固然,這意味着若是你願意,你能夠輕鬆定義現代REST風格的URL模式。在第15章和第16章中能夠找到關於URL路由的完整描述。
Clean URLs were hard to implement in earlier frameworks, but ASP.NET Core MVC uses a feature known as URL routing to provide clean URLs by default. This gives you control over your URL schema and its relationship to your application, offering you the freedom to create a pattern of URLs that is meaningful and useful to your users, without the need to conform to a predefined pattern. And, of course, this means you can easily define a modern REST-style URL schema if you want. You’ll find a thorough description of URL routing in Chapters 15 and 16.
微軟的.NET平臺隨着每一個主要版本的發展而發展,支持了乃至定義了現代編程的最新技術。ASP.NET Core MVC是爲.NET Core構建的,所以它的API可充分利用C#程序員熟悉的語言和運行時創新,包括await關鍵字、擴展方法、lambda表達式、匿名類型、動態類型以及LINQ。
Microsoft’s .NET platform has evolved with each major release, supporting—and even defining—the state-of-the-art aspects of modern programming. ASP.NET Core MVC is built for .NET Core, so its API can take full advantage of language and runtime innovations familiar to C# programmers, including the await keyword, extension methods, lambda expressions, anonymous and dynamic types, and Language Integrated Query (LINQ).
ASP.NET Core MVC API方法和編碼模式遵循比之前的平臺更清晰、更具表現力的組成方式。若是你對最新的C#語言功能不熟悉,不要擔憂,在第4章中提供了MVC開發最重要的C#特性的總結。
Many of the ASP.NET Core MVC API methods and coding patterns follow a cleaner, more expressive composition than was possible with earlier platforms. Don’t worry if you are not up to speed with the latest C# language features; I provide a summary of the most important C# features for MVC development in Chapter 4.
之前的ASP.NET版本特定於Windows,須要在Windows中編寫Web應用程序和Windows服務器才能部署和運行它們。微軟爲ASP.NET Core提供了跨平臺的開發和部署方案。.NET Core可用於不一樣的平臺,包括MacOS和一系列流行的Linux發行版。跨平臺支持使得部署ASP.NET Core MVC應用程序變得更加容易,而且能夠很好地支持Docker等應用程序容器平臺。
Previous versions of ASP.NET were specific to Windows, requiring a Windows desktop to write web applications and a Windows server to deploy and run them. Microsoft made ASP.NET Core cross- platform, both for development and for deployment. .NET Core is available for different platforms, including macOS and a range of popular Linux distributions. Cross-platform support makes it easier to deploy ASP.NET Core MVC applications, and there is good support for working with application container platforms, such as Docker.
大多數ASP.NET Core MVC開發極可能都會使用Visual Studio來完成,但微軟也建立了一個名爲Visual Studio Code的跨平臺開發工具,這意味着ASP.NET Core MVC開發再也不侷限於Windows。
Most ASP.NET Core MVC development is likely to be done using Visual Studio for the immediate future, but Microsoft has also created a cross-platform development tool called Visual Studio Code, which means that ASP.NET Core MVC development is no longer restricted to Windows.
與之前的Microsoft Web開發平臺不一樣,你能夠自由下載ASP.NET Core和ASP.NET Core MVC的源代碼,甚至修改和編譯本身的版本。當你的調試跟蹤進入到系統組件中,而且想要進入其代碼(甚至讀取原始程序員的註釋)時,這是很是寶貴的。 若是正在構建高級組件,並但願查看存在哪些開發可能性或內置組件實際如何工做,這也頗有用。
能夠從 https://github.com/aspnet 下載ASP.NET Core和ASP.NET Core MVC的源代碼。
Unlike previous Microsoft web development platforms, you are free to download the source code for ASP. NET Core and ASP.NET Core MVC and even modify and compile your own version of it. This is invaluable when your debugging trail leads into a system component and you want to step into its code (and even read the original programmer’s comments). It is also useful if you are building an advanced component and want to see what development possibilities exist or how the built-in components actually work.
You can download the ASP.NET Core and ASP.NET Core MVC source code from https://github.com/ aspnet.
爲了充分利用本書,你應該熟悉Web開發的基礎知識,瞭解HTML和CSS的工做原理,並掌握C#的相關知識。若是你對客戶端細節(如JavaScript)有點模糊不要擔憂,個人重點是本書中的服務器端開發,能夠經過示例找到所須要的內容。在第4章中,我總結了MVC開發最有用的C#語言特性,若是你正在遷移到最新的.NET版本,那麼你會發現它頗有用。
To get the most from this book, you should be familiar with the basics of web development, understand how HTML and CSS work, and have a working knowledge of C#. Don’t worry if you are a little hazy on the client- side details, such as JavaScript. My emphasis is on server-side development in this book, and you can pick up what you need through the examples. In Chapter 4, I summarize the most useful C# language features for MVC development, which you’ll find useful if you are moving to the latest .NET versions from an earlier release.
本書分爲兩部分,每一部分都包括了一系列相關話題。
This book is split into two parts, each of which covers a set of related topics.
Part 1: ASP.NET Core MVC的介紹
我將從」所謂ASP.NET Core MVC「開始撰寫本書。我將解釋了MVC模式的優勢和實際影響,介紹ASP.NET Core MVC適用於現代Web開發的方式,並描述了每一個ASP.NET Core MVC程序員都須要的工具和C#語言的功能。
Part 1: Introducing ASP.NET Core MVC
I start this book by putting ASP.NET Core MVC in context. I explain the benefits and practical impact of the MVC pattern, cover the way in which ASP.NET Core MVC fits into modern web development, and describe the tools and C# language features that every ASP.NET Core MVC programmer needs.
在第2章中,將經過建立一個簡單的Web應用程序,深刻了解主要組件和功能模塊,以及如何將他們組合在一塊兒。這本書的大部份內容交給了一個名爲SportsStore的項目的開發,經過這個項目,我將向你展現從開始到部署的實際開發過程,並涉及ASP.NET Core MVC的主要功能。
In Chapter 2, you will dive right in by creating a simple web application and will get an idea of what the major components and building blocks are and how they fit together. Most of this part of the book, however, is given over to the development of a project called SportsStore, through which I show you a realistic development process from inception to deployment, touching on the major features of ASP.NET Core MVC.
Part 2: ASP.NET Core MVC的詳細說明
在第2部分中,我解釋了用於構建SportsStore應用程序的ASP.NET Core MVC功能的內部工做原理。我向你展現每一個功能的工做原理,說明它所扮演的角色,並向你展現可用的配置和自定義選項。在第1部分中設定了普遍的語境以後,我深刻了解了第2部分中的細節。
Part 2: ASP.NET Core MVC in Detail
In Part 2, I explain the inner workings of ASP.NET Core MVC features that I used to build the SportsStore application. I show you how each feature works, explain the role it plays, and show you the configuration and customization options that are available. Having set the broad context in Part 1, I dig right into the details in Part 2.
能夠從 https://github.com/apress/pro... 下載本書中全部章節的示例項目。該下載是免費的,幷包含從新建立示例所需的全部支持資源,而無需輸入它們。下載代碼不是必須的,但它是實驗的最簡單方法,能夠輕鬆地將代碼複製並粘貼到本身的項目中。
You can download the example projects for all the chapters in this book from https://github.com/apress/ pro-asp.net-core-mvc-2. The download is available without charge and includes all the supporting resources that are required to re-create the examples without having to type them in. You don’t have to download the code, but it is the easiest way of experimenting with the examples and makes it easy to copy and paste code into your own projects.
在本章中,我解釋了什麼是ASP.NET Core MVC以及它是如何從Web Forms和原始的ASP.NET MVC Framework發展而來的。我描述了使用ASP.NET Core MVC的好處以及本書的結構。在下一章中,將講解ASP.NET Core MVC的實際操做,並簡要演示了提供這些優點的功能。
In this chapter, I explained the context in which ASP.NET Core MVC exists and how it has evolved from Web Forms and the original ASP.NET MVC Framework. I described the benefits of using the ASP.NET Core MVC and the structure of this book. In the next chapter, you’ll see ASP.NET Core MVC in action in a simple demonstration of the features that deliver these benefits.