Preface
Until now, creating interactive web pages meant using JavaScript. But with Blazor, Microsoft's new way to create .NET web applications, developers can easily build interactive and rich web applications using C#. This book will guide you through the most commonly encountered scenarios when starting your journey with Blazor.
Firstly, you'll discover how to leverage the power of Blazor and learn what you can do with both the server side and WebAssembly. By showing you how all the elements work together practically, the book will help you solve some of the common roadblocks that developers face. As you advance, you'll learn how to create server-side Blazor and Blazor WebAssembly projects, how Razor syntax works, and how to validate forms and create your own components. The book then introduces you to the key concepts involved in web development with Blazor, which you will be able to put into practice straight away.
By the end of this Blazor book, you'll have gained the confidence to create and deploy production-ready Blazor applications.
What this book covers
Chapter 1, Hello Blazor, will teach you about the difference between server-side and client-side Blazor. You will get an overview of how the technology works and a brief history of where Blazor comes from. Knowing the structure and differences between the hosting models is essential for understanding the technology.
Chapter 2, Creating Your First Blazor App, helps you understand how to install and set up your development environment. You will create your first Blazor app (both server-side and client-side) and learn about the structure of the project template.
Chapter 3, Introducing Entity Framework Core, teaches you how to create your database where you will store your data (blog posts, categories, and tags). You will be using the dotnet tool to create a new project to get a feel for the tool.
Chapter 4, Understanding Basic Blazor Components, digs deeper into components, life cycle events, adding parameters, and sharing parameters between components. You will also create reusable components in this chapter.
Chapter 5, Creating Advanced Blazor Components, digs even deeper into components, adding functionality such as child components, cascading parameters, and values, and covering how to use actions and callbacks.
Chapter 6, Building Forms with Validation, takes a look at forms, how to validate forms, and how to build your own validation mechanism. This chapter will cover the most common use cases when it comes to handling forms, such as file upload, text, numbers, and triggering code when checking a checkbox.
Chapter 7, Creating an API, looks at creating an API. When using Blazor WebAssembly, we need an API to get data.
Chapter 8, Authentication and Authorization, looks at adding authentication and authorization to Blazor and making sure navigation such as redirecting to a login page works as expected.
Chapter 9, Sharing Code and Resources, teaches you how it is possible to share code between client-side and server-side Blazor projects by adding all the things you need into a shared library. In this chapter, you will build a shared library that can be packaged as a NuGet package and shared with others.
Chapter 10, JavaScript Interop, explores how you can leverage JavaScript libraries when using Blazor and make calls from C# to JavaScript. You will also take a look at how JavaScript is able to call C# functions in our Blazor app.
Chapter 11, Managing State, looks into the different ways of managing state (persisting data), such as using LocalStorage or just keeping data in memory by using dependency injection. You will not only cover persisting data in a database, but you will also cover how dependency injection works on the different project types.
Chapter 12, Debugging, teaches you how to debug your applications and add extended logging to figure out what's wrong in your application. You will not only look at traditional debugging but also at debugging C# code directly from within the web browser.
Chapter 13, Testing, looks at automated testing so that you can make sure your components work as they should (and continue to do so). There is no built-in method to test Blazor applications but there is a really good community project called bUnit.
Chapter 14, Deploying to Production, will take you through the different things you need to think about when it comes to running Blazor in production.
Chapter 15, Where to Go from Here, is a short chapter with a call to action, some resources you can use, and a finale.
To get the most out of this book
I recommend that you read the first few chapters to make sure that you are up to speed with the basic concepts of Blazor in general. The project we are creating is adapted for real-world use but some parts are left out, such as proper error handing. You should, however, get a good grasp of the building blocks of Blazor.
The book focuses on using Visual Studio 2019; that said, though, feel free to use whatever version you are comfortable with that supports Blazor.

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
I would love for you to share your progress while reading this book or in Blazor development in general. Tweet me @EngstromJimmy
.
I hope you have as much fun reading this book as I had writing it.
Download the example code files
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Web-Development-with-Blazor. In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781800208728_ColorImages.pdf.
Conventions used
There are a number of text conventions used throughout this book.
Code in text
: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "In this case, when the page gets downloaded, it will trigger a download of the blazor.webassembly.js
file."
A block of code is set as follows:
public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddServerSideBlazor(); services.AddSingleton<WeatherForecastService>(); }
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
<div class="top-row pl-4 navbar navbar-dark"> <a class="navbar-brand" href="">MyBlogServerSide</a> <button class="navbar-toggler" @onclick="ToggleNavMenu">
Any command-line input or output is written as follows:
dotnet new blazorserver -o BlazorServerSideApp cd MyBlog.Data
Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."
Tips or important notes
Appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at customercare@packtpub.com.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Share Your Thoughts
Once you've read Web Development with Blazor, we'd love to hear your thoughts! Scan the QR code below to go straight to the Amazon review page for this book and share your feedback.

https://www.amazon.in/review/create-review/error?asin=1-800-20872-3&
Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.