ebook img

ASP.NET core recipes : a problem-solution approach PDF

447 Pages·2017·6.74 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 : a problem-solution approach

ASP.NET Core Recipes A Problem-Solution Approach — Second Edition — John Ciliberti 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 This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Cover image by Freepik (www.freepik.com) Managing Director: Welmoed Spahr Editorial Director: Todd Green Acquisitions Editor: Todd Green Development Editor: Anne Marie Walker Technical Reviewer: Damien Foggon Coordinating Editor: Mark Powers Copy Editor: Kim Wimpsett Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected], or visit www.apress.com/ rights-permissions. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at www.apress.com/bulk-sales. 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. Printed on acid-free paper Dedicated to my daughter Katrina who never takes my iPad so she can watch Netflix. Contents at a Glance About the Author ����������������������������������������������������������������������������������������������������xxi About the Technical Reviewer ������������������������������������������������������������������������������xxiii Acknowledgments �������������������������������������������������������������������������������������������������xxv 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 v Contents About the Author ����������������������������������������������������������������������������������������������������xxi About the Technical Reviewer ������������������������������������������������������������������������������xxiii Acknowledgments �������������������������������������������������������������������������������������������������xxv 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 vii ■ Contents 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 viii ■ Contents 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 ix ■ Contents ■ 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 x ■ Contents 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 xi

Description:
Quickly find solutions to common web development problems. Content is presented in the popular problem-solution format. Look up the problem that you want to solve. Read the solution. Apply the solution directly in your own code. Problem solved!ASP.NET Core Recipes is a practical guide for developers
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.