مشخصات کتاب
-
Jess Chadwick
-
2014
-
انگلیسی
-
20999
-
1086
-
0
Programming Razor
دوره آموزش MVC
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
A Brief History of Microsoft’s Web Development Platforms 1
Active Server Pages (ASP) 1
ASP.NET Web Forms 2
ASP.NET MVC 2
WebMatrix 2
Hello, Razor! 3
Differentiating Code and Markup 4
Code Nuggets 4
Code Blocks 4
How Razor Parses Markup and Code 6
Disambiguating Code and Markup 7
Comments 9
2. Razor and Microsoft WebMatrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Introducing ASP.NET Web Pages 11
Installing WebMatrix 11
Your First WebMatrix Website 12
The File List View 12
Website Administration 12
Hello World, Razor Style 14
Data Access with WebMatrix 14
Creating a Database 14
Populating the Database with Data 15
Displaying Data from the Database 16
Handling Posted Form Data 18
Saving Data to the Database 19
Validating Posted Data 20
Creating the Home Page 25
3. Organizing Razor Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Layouts 27
Layouts Are Pages, Too! 29
Sections 31
IsSectionDefined 32
Nested Layouts 32
Nested Layouts and Sections 33
Redefining Sections 34
The Layout Rendering Life Cycle 35
Nested Layouts 37
Partial Views 37
Creating Partial Views 37
Reusing Partial Views 39
Razor Helpers 41
Razor Helper Packages 44
Razor Helpers versus Partial Views 44
Razor Helpers 45
Partial Views 45
Executing Common Code 45
Executing Code the First Time a Page Executes 45
Executing Code Every Time a Page Executes 46
Wrapping Views with _PageStart.cshtml Logic 47
Executing Multiple _PageStart.cshtml Templates 47
4. Razor and ASP.NET MVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Installing ASP.NET MVC 51
The Model-View-Controller Architecture 52
ASP.NET MVC View Engines 52
The Razor View Engine 53
Implementing a Blog Site Using ASP.NET MVC 54
The Model 56
The Controller 56
Convention versus Configuration 59
Authoring ASP.NET MVC Views with the Razor Syntax 60
Adding Razor Views to an ASP.NET MVC Application 60
Writing ASP.NET MVC Razor View Markup 61
Strongly-Typed Views 62
Changing the Base Class 63
Applying Custom Base Classes to Multiple Views 65
Layouts and Content Pages 66
Razor View File Locations 66
Controller Views 67
Locating Razor Views 67
Shared Views 68
Views in ASP.NET MVC Areas 68
Html and Url Helper Classes 70
ASP.NET MVC’s Razor View Page Rendering Life Cycle 71
Precompiling Razor Views 71
5. The Razor API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Razor Templates: From Markup to .NET Code 75
1. Parse the Razor Template 76
2. Generate .NET Code 76
3. Compile Generated Code into an Executable Class 77
4. Instantiate and Execute the Generated Class 77
Meet the Players 78
Configuring the Razor Template Engine 79
Creating a RazorEngineHost 79
Creating the RazorTemplateEngine 80
Compiling Razor Templates 80
Executing a Razor Template 81
Advanced Templating Logic 81
6. Advanced Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Inline Templates and Templated Delegates 83
Sharing Views Between Projects 85
The Razor Single File Generator 85
Creating Reusable ASP.NET MVC Views 86
Creating Reusable ASP.NET MVC Helpers 90
Razor Single File Generator Generator Implementations 92
Unit Testing Razor Views 93
Applying Razor to Text-Based Scenarios 95
7. Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99