ebook img

ASP.NET Core Recipes 2nd ed. PDF

442 Pages·2017·5.376 MB·english
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview ASP.NET Core Recipes 2nd ed.

ASP.NET Core Recipes A Problem-Solution Approach Second Edition John Ciliberti ASP.NET Core Recipes: A Problem-Solution Approach John Ciliberti Sparta, New Jersey, USA ISBN-13 (pbk): 978-1-4842-0428-3 ISBN-13 (electronic): 978-1-4842-0427-6 DOI 10.1007/978-1-4842-0427-6 Library of Congress Control Number: 2017953377 Copyright © 2017 by John Ciliberti Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/9781484204283. For more detailed information, please visit www.apress.com/source-code. Contents at a Glance Introduction� ��������������������������������������������������������������������������������������������������������xxvii ■ Chapter 1: ASP�NET Core MVC Fundamentals ��������������������������������������������������������1 ■ Chapter 2: Getting Started with ASP�NET Core MVC ���������������������������������������������43 ■ Chapter 3: MVC Razor Syntax and HTML Helpers ������������������������������������������������67 ■ Chapter 4: Using Tag Helpers ����������������������������������������������������������������������������101 ■ Chapter 5: Getting the Most from the New Features in ASP�NET Core MVC �������139 ■ Chapter 6: Solution Design Using ASP�NET Core MVC ����������������������������������������171 ■ Chapter 7: Test-Driven Development with ASP�NET Core MVC ���������������������������221 ■ Chapter 8: Moving from Web Forms to ASP�NET Core MVC ��������������������������������251 ■ Chapter 9: Data Validation Using ASP�NET Core MVC �����������������������������������������295 ■ Chapter 10: Securing Your ASP�NET Core MVC Application �������������������������������335 ■ Chapter 11: Creating Modern User Experiences Using React�js and ASP�NET Core �����������������������������������������������������������������������������������������������������361 ■ Appendix ������������������������������������������������������������������������������������������������������������411 Index ���������������������������������������������������������������������������������������������������������������������425 Contents Introduction� ��������������������������������������������������������������������������������������������������������xxvii ■ Chapter 1: ASP�NET Core MVC Fundamentals ��������������������������������������������������������1 1-1. Understanding the Microsoft Web Development Ecosystem ....................................1 Problem ..................................................................................................................................................1 Solution...................................................................................................................................................2 How It Works ...........................................................................................................................................2 1-2. Understanding the MVC Pattern ..............................................................................11 Problem ................................................................................................................................................11 Solution.................................................................................................................................................11 How It Works .........................................................................................................................................12 1-3. Understanding the Differences Between MVC, MVVM, and MVP ............................14 Problem ................................................................................................................................................14 Solution.................................................................................................................................................15 How It Works .........................................................................................................................................15 1-4. Discovering the Features of ASP.NET Core MVC .....................................................17 Problem ................................................................................................................................................17 Solution.................................................................................................................................................17 How It Works .........................................................................................................................................17 1-5. Understanding the Architecture of ASP.NET Core MVC ...........................................22 Problem ................................................................................................................................................22 Solution.................................................................................................................................................22 How It Works .........................................................................................................................................23 1-6. Understanding Models in ASP.NET Core MVC ..........................................................30 Problem ................................................................................................................................................30 Solution.................................................................................................................................................30 How It Works .........................................................................................................................................31 1-7. Understanding Controllers and Actions in ASP.NET Core MVC ................................33 Problem ................................................................................................................................................33 Solution.................................................................................................................................................33 How It Works .........................................................................................................................................34 1-8. Understanding Page Routing in ASP.NET Core MVC ................................................37 Problem ................................................................................................................................................37 Solution.................................................................................................................................................37 How It Works .........................................................................................................................................37 1-9. Understanding View Engines in ASP.NET Core MVC ................................................39 Problem ................................................................................................................................................39 Solution.................................................................................................................................................40 How It Works .........................................................................................................................................40 ■ Chapter 2: Getting Started with ASP�NET Core MVC ���������������������������������������������43 2-1. Setting Up Your Development Environment ............................................................43 Problem ................................................................................................................................................43 Solution.................................................................................................................................................43 How It Works .........................................................................................................................................44 2-2. Determining Which Operating System to Use for Your Development Machine .......47 Problem ................................................................................................................................................47 Solution.................................................................................................................................................48 How It Works .........................................................................................................................................48 2-3. Creating a New ASP.NET Core MVC Application Using Visual Studio 2017 ..............50 Problem ................................................................................................................................................50 Solution.................................................................................................................................................50 How It Works .........................................................................................................................................51 2-4. Creating a New ASP.NET Core MVC Application Using dotnet.exe ..........................51 Problem ................................................................................................................................................51 Solution.................................................................................................................................................51 How It Works .........................................................................................................................................51 2-5. Understanding the Structure of an ASP.NET Core MVC Project ...............................53 Problem ................................................................................................................................................53 Solution.................................................................................................................................................53 How It Works .........................................................................................................................................53 2-6. Using Visual Studio’s Debugging Windows to Debug an ASP.NET Core MVC Application ......................................................................................................57 Problem ................................................................................................................................................57 Solution.................................................................................................................................................57 How It Works .........................................................................................................................................58 2-7. Setting a Conditional Breakpoint in an ASP.NET Core MVC Controller ....................60 Problem ................................................................................................................................................60 Solution.................................................................................................................................................60 How It Works .........................................................................................................................................60 2-8. Testing Your ASP.NET Core MVC Application Across Many Browsers at the Same Time ....................................................................................................62 Problem ................................................................................................................................................62 Solution.................................................................................................................................................63 How It Works .........................................................................................................................................63 2-9. Editing Your Views and Layouts from Inside Internet Explorer................................64 Problem ................................................................................................................................................64 Solution.................................................................................................................................................64 How It Works .........................................................................................................................................64 ■ Chapter 3: MVC Razor Syntax and HTML Helpers ������������������������������������������������67 3-1. Understanding Razor Syntax ...................................................................................67 Problem ................................................................................................................................................67 Solution.................................................................................................................................................67 How It Works .........................................................................................................................................68 3-2. Creating an Action Link ...........................................................................................75 Problem ................................................................................................................................................75 Solution.................................................................................................................................................75 How It Works .........................................................................................................................................76 3-3. Creating an Action Link to Another Controller .........................................................79 Problem ................................................................................................................................................79 Solution.................................................................................................................................................79 How It Works .........................................................................................................................................80 3-4. Creating an Action Link to Another Area .................................................................80 Problem ................................................................................................................................................80 Solution.................................................................................................................................................80 How It Works .........................................................................................................................................81 3-5. Creating an Action Link with Custom HTML Attributes ...........................................81 Problem ................................................................................................................................................81 Solution.................................................................................................................................................82 How It Works .........................................................................................................................................82 3-6. Creating an Action Link That Uses HTTPS ...............................................................82 Problem ................................................................................................................................................82 Solution.................................................................................................................................................83 How It Works .........................................................................................................................................83 3-7. Creating Your Own Action Link for Creating HTTPS Links .......................................84 Problem ................................................................................................................................................84 Solution.................................................................................................................................................84 How It Works .........................................................................................................................................85 3-8. Creating an Action Link with an Anchor Target .......................................................86 Problem ................................................................................................................................................86 Solution.................................................................................................................................................86 How It Works .........................................................................................................................................86 3-9. Creating an Image Link ...........................................................................................90 Problem ................................................................................................................................................90 Solution.................................................................................................................................................90 How It Works .........................................................................................................................................90 3-10. Creating an Image Link Using a Bootstrap Glyphicon ...........................................90 Problem ................................................................................................................................................90 Solution.................................................................................................................................................90 How It Works .........................................................................................................................................91 3-11. Using HTML Helpers to Create HTML Form Elements ...........................................91 Problem ................................................................................................................................................91 Solution.................................................................................................................................................92 How It Works .........................................................................................................................................92 3-12. Using Strongly Typed HTML Helpers .....................................................................95 Problem ................................................................................................................................................95 Solution.................................................................................................................................................95 How It Works .........................................................................................................................................96 3-13. Using Templated HTML Helpers ............................................................................97 Problem ................................................................................................................................................97 Solution.................................................................................................................................................97 How It Works .........................................................................................................................................98 3-14. Creating an Inline Function in a Razor View .........................................................99 Problem ................................................................................................................................................99 Solution.................................................................................................................................................99 How It Works .......................................................................................................................................100 ■ Chapter 4: Using Tag Helpers ����������������������������������������������������������������������������101 4-1. Understanding Tag Helpers ...................................................................................101 Problem ..............................................................................................................................................101 Solution...............................................................................................................................................101 How It Works .......................................................................................................................................103 4-2. Creating Hyperlinks with the Anchor Tag Helper ...................................................104 Problem ..............................................................................................................................................104 Solution...............................................................................................................................................104 How It Works .......................................................................................................................................105 4-3. Building a Form Using the Form, Label, and Input Tag Helpers ............................107 Problem ..............................................................................................................................................107 Solution...............................................................................................................................................107 How It Works .......................................................................................................................................107 4-4. Data Binding a Nullable bool to an Option Tag Helper ..........................................112 Problem ..............................................................................................................................................112 Solution...............................................................................................................................................112 How It Works .......................................................................................................................................112 4-5. Creating a Drop-Down List with the Select Tag Helper .........................................114 Problem ..............................................................................................................................................114 Solution...............................................................................................................................................114 How It Works .......................................................................................................................................115 4-6. Validating Input with Tag Helpers ..........................................................................118 Problem ..............................................................................................................................................118 Solution...............................................................................................................................................118 How It Works .......................................................................................................................................119 4-7. Improving Performance with the Cache Tag Helper ..............................................124 Problem ..............................................................................................................................................124 Solution...............................................................................................................................................124 How It Works .......................................................................................................................................124 4-8. Using the Environment, Script, and Link Tag Helpers for Conditionally Rendering Script and Link Tags ............................................................................132 Problem ..............................................................................................................................................132 Solution...............................................................................................................................................132 How It Works .......................................................................................................................................132 4-9. Creating a Custom Tag Helper...............................................................................134 Problem ..............................................................................................................................................134 Solution...............................................................................................................................................134 How It Works .......................................................................................................................................134 ■ Chapter 5: Getting the Most from the New Features in ASP�NET Core MVC �������139 5-1. Understanding NuGet with ASP.NET Core MVC .....................................................139 Problem ..............................................................................................................................................139 Solution...............................................................................................................................................139 How It Works .......................................................................................................................................140 5-2. Upgrading from ASP.NET MVC 5 to ASP.NET Core MVC .........................................144 Problem ..............................................................................................................................................144 Solution...............................................................................................................................................145 How It Works .......................................................................................................................................145 5-3. Upgrading from Web API to ASP.NET MVC 6 ..........................................................148 Problem ..............................................................................................................................................148 Solution...............................................................................................................................................148 How It Works .......................................................................................................................................149 5-4. Creating a Tag Cloud Using a View Component ....................................................158 Problem ..............................................................................................................................................158 Solution...............................................................................................................................................158 How It Works .......................................................................................................................................158 5-5. Using the Inject Feature to Implement a Hit Counter ............................................166 Problem ..............................................................................................................................................166 Solution...............................................................................................................................................166 How It Works .......................................................................................................................................167

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.