Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Blazor WebAssembly by Example
Blazor WebAssembly by Example

Blazor WebAssembly by Example: A project-based guide to building web apps with .NET, Blazor WebAssembly, and C#

eBook
$9.99 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Blazor WebAssembly by Example

Chapter 1: Introduction to Blazor WebAssembly

Blazor WebAssembly is Microsoft's new single-page application (SPA) framework for building web applications on .NET Framework. It enables developers to run C# code on the client. Therefore, instead of being forced to use JavaScript on the browser, we can now use C# on the browser.

In this chapter, we will prepare you to develop web applications using Blazor WebAssembly. We will discuss the two different Blazor hosting models and present the advantages of using Blazor WebAssembly over Blazor Server. Finally, we will guide you through the process of setting up your computer to complete the projects in this book.

In this chapter, we will cover the following topics:

  • Benefits of using the Blazor framework
  • Differences between the two hosting models
  • What is WebAssembly?
  • Setting up your PC

Benefits of using the Blazor framework

Using the Blazor framework has several benefits. For starters, it is a free and open source framework built on Microsoft's robust .NET Framework. Also, it is an SPA framework that uses Razor syntax and can be developed using Microsoft's exceptional tooling.

.NET Framework

Blazor is built on .NET Framework. Since Blazor is built on .NET Framework, anyone familiar with .NET Framework can quickly become productive using the Blazor framework. The Blazor framework leverages the robust ecosystem of .NET libraries and NuGet packages from .NET Framework. Also, since both client and server code are written in C#, they can share code and libraries, such as the application logic used for data validation.

Blazor is open source. Since Blazor is a feature of the ASP.NET framework, all of the source code for Blazor is available on GitHub as part of the dotnet/aspnetcore repository that is owned by the .NET Foundation. .NET Foundation is an...

Hosting models

Blazor has two different hosting models. The first hosting model that Microsoft released is the Blazor Server model. In this hosting model, the web app is executed on the server. The second hosting model that Microsoft released, and the topic of this book, is the Blazor WebAssembly model. In this hosting model, the web app is executed on the browser.

Each hosting model has its own advantages and disadvantages. However, they both use the same underlying architecture. Therefore, it is possible to write and test your code independent of the hosting model. The major differences between the two hosting models concern latency, security, data access, and offline support.

Blazor Server

As we just mentioned, the Blazor Server hosting model was the first hosting model released by Microsoft. It was released as part of the .NET Core 3 release in September 2019.

The following diagram illustrates the Blazor Server hosting model:

Figure 1.1 –...

What is WebAssembly?

WebAssembly is a binary instruction format that allows code written in C# to run on the browser at near-native speed. To run .NET binaries in a web browser, it uses a version of the .NET runtime that has been compiled to WebAssembly. You can think of it as executing natively compiled code in a browser.

WebAssembly is an open standard developed by a W3C Community Group. It was originally announced in 2015, and the first browser that supported it was released in 2017.

WebAssembly goals

When WebAssembly was originally being developed, there were four main design goals for the project:

  • Fast and efficient
  • Safe
  • Open
  • Don't break the web

WebAssembly is fast and efficient. It is designed to allow developers to write code in any language that can then be compiled to run in the browser. Since the code is compiled, it is fast and performs at near-native speed.

WebAssembly is safe. It does not allow direct interaction with the browser...

Setting up your PC

For the projects in this book, we use Visual Studio 2019, .NET 5.0, and SQL Server 2019.

All of the projects are built using Visual Studio 2019 Community Edition version 16.9.5 with the ASP.NET and Web Development workload. If you need to install Visual Studio 2019, follow the directions in the Installing Visual Studio Community Edition section later in this chapter.

Tip

Although we are using Visual Studio 2019 Community Edition, any edition of Visual Studio 2019 can be used to complete the projects in this book. Microsoft Visual Studio Code can also be used.

Blazor WebAssembly in .NET 5 requires .NET 5.0. To check the version of .NET that is running on your computer, open the Command Prompt and enter the following command:

dotnet –-version

If your computer is not running .NET 5.0, follow the directions in the Installing .NET 5.0 section later in this chapter.

The final two projects in this book use SQL Server 2019 Express Edition as...

Summary

After completing this chapter, you should understand the benefits of using Blazor WebAssembly versus other web development frameworks and be prepared to complete the projects in this book.

In this chapter, we introduced the Blazor framework. The Blazor framework is built on .NET Framework and allows developers to use C# on both the frontend and backend of a web app.

After that, we compared Blazor Server with Blazor WebAssembly. Blazor WebAssembly has many advantages over Blazor Server due to the fact that it runs on the browser while Blazor Server runs on the server. A Blazor WebAssembly web app can run offline and feels much more like a native application because all of the code is run directly on the browser. Finally, a Blazor WebAssembly app can be easily converted into a PWA.

In the last part of the chapter, we explained how to set up your computer with Visual Studio 2019 Community Edition, .NET 5.0, and SQL Server 2019 Express, all of which are required to complete...

Questions

The following questions are provided for your consideration:

  1. Does using Blazor WebAssembly mean that you never need to write JavaScript ever again?
  2. Does Blazor WebAssembly require that any plugins be installed on the browser?
  3. How much does it cost to get started developing with Blazor WebAssembly?

Further reading

The following resources provide more information concerning the topics in this chapter:

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Explore complete, easy-to-follow web projects using Blazor
  • Build projects such as a weather app, expense tracker, and Kanban board with real-world applications
  • Understand and work with Blazor WebAssembly effectively without spending too much time focusing on the theory

Description

Blazor WebAssembly makes it possible to run C# code on the browser instead of having to use JavaScript, and does not rely on plugins or add-ons. The only technical requirement for using Blazor WebAssembly is a browser that supports WebAssembly, which, as of today, all modern browsers do. Blazor WebAssembly by Example is a project-based guide for learning how to build single-page web applications using the Blazor WebAssembly framework. This book emphasizes the practical over the theoretical by providing detailed step-by-step instructions for each project. You'll start by building simple standalone web applications and progress to developing more advanced hosted web applications with SQL Server backends. Each project covers a different aspect of the Blazor WebAssembly ecosystem, such as Razor components, JavaScript interop, event handling, application state, and dependency injection. The book is designed in such a way that you can complete the projects in any order. By the end of this book, you will have experience building a wide variety of single-page web applications with .NET, Blazor WebAssembly, and C#.

Who is this book for?

This book is for .NET web developers who are tired of constantly learning new JavaScript frameworks and wish to write web applications using Blazor WebAssembly, leveraging the power of .NET and C#. The book assumes beginner-level knowledge of the C# language, .NET framework, Microsoft Visual Studio, and web development concepts.

What you will learn

  • Discover the power of the C# language for both server-side and client-side web development
  • Use the Blazor WebAssembly App project template to build your first Blazor WebAssembly application
  • Use templated components and the Razor class library to build and share a modal dialog box
  • Understand how to use JavaScript with Blazor WebAssembly
  • Build a progressive web app (PWA) to enable native app-like performance and speed
  • Understand dependency injection (DI) in .NET to build a shopping cart app
  • Get to grips with .NET Web APIs by building a task manager app
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 09, 2021
Length: 266 pages
Edition : 1st
Language : English
ISBN-13 : 9781800567511
Vendor :
Microsoft
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : Jul 09, 2021
Length: 266 pages
Edition : 1st
Language : English
ISBN-13 : 9781800567511
Vendor :
Microsoft
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 173.97
Web Development with Blazor
$49.99
Blazor WebAssembly by Example
$43.99
C# 10 and .NET 6 – Modern Cross-Platform Development
$79.99
Total $ 173.97 Stars icon
Banner background image

Table of Contents

10 Chapters
Chapter 1: Introduction to Blazor WebAssembly Chevron down icon Chevron up icon
Chapter 2: Building Your First Blazor WebAssembly Application Chevron down icon Chevron up icon
Chapter 3: Building a Modal Dialog Using Templated Components Chevron down icon Chevron up icon
Chapter 4: Building a Local Storage Service Using JavaScript Interoperability (JS Interop) Chevron down icon Chevron up icon
Chapter 5: Building a Weather App as a Progressive Web App (PWA) Chevron down icon Chevron up icon
Chapter 6: Building a Shopping Cart Using Application State Chevron down icon Chevron up icon
Chapter 7: Building a Kanban Board Using Events Chevron down icon Chevron up icon
Chapter 8: Building a Task Manager Using ASP.NET Web API Chevron down icon Chevron up icon
Chapter 9: Building an Expense Tracker Using the EditForm Component Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(12 Ratings)
5 star 66.7%
4 star 16.7%
3 star 16.7%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Jul 14, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Packt never fails to impress with their content. Blazor WASM is an awesome new tool and this teaches you everything you need to know to make a well designed application. Like all Packt books, it is easy to pick up in different chapters depending on what you want to learn. I was specifically looking more into how to make a PWA with Blazor and this was a fantastic guide!
Amazon Verified review Amazon
Paul Schroeder Jul 26, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I appreciate the author’s “no fluff” approach to covering all the basics Blazor developers need to know. As someone who has developed a few Blazor applications already, this meant that I was able to finish the content in just a few sessions. Being somewhat experienced, I certainly did pick up some new information, but I think beginner-to-intermediate developers will get the most out of this book.Personally, I thought the use of project templates was very appropriate and I wish more Visual Studio developers made use of this gem of an IDE feature. The sections on RenderFragment, EventCallback, CSS isolation, attribute splatting, and JS Interop were explained nicely. Content on Progressive Web Apps contained details, like the service worker life cycle, that were good to learn more about.I was impressed at the author’s ability to present straightforward examples, each of which demonstrated a Blazor capability with minimal code. Sticking close to just what is needed made it easy to understand what was happening.Overall, I liked this book, which is clearly designed to be a quick overview of each topic. After covering the basics, the author provides “further reading” sections at the conclusion of each chapter to make it easy to go deeper, if desired. There are also sample questions along the way that help you gauge your knowledge or think about what could be next if you want to experiment with extending the project samples.
Amazon Verified review Amazon
Adam Smith Apr 10, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book has a very pleasant way of teaching. A kind of step-by-step way. I give it a full 5 stars.
Amazon Verified review Amazon
Daniel Correa Aug 08, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Blazor WebAssembly is the Microsoft's single-page application (SPA) framework for building web applications on .NET Framework. It is another option that front-end developers should have in mind. One of the main difference with their main competitors (Vue, React, Angular) is that it enables developers to run C# code on the client. It means, you can develop an entire SPA application without using JavaScript.Toi (the author of this book) teaches us how to use Blazor WebAssembly in a practical way. She provides a set of projects and examples which are very useful and which teaches us the fundamental elements of Blazor WebAssembly. For example, (i) you will implement a simple modal dialog application, which focuses on razor elements, components, and RenderFragments. (ii) You will implement a simple data storage application, which explains how to use JS Interop to execute some JavaScript commands from a Blazor WebAssembly application (there are some cases in which using JavaScript makes sense). (iii) You will implement a Weather App which uses service workers, APIs, and implementation of PWA applications. And (iv) even, it takes you to develop a complete front-end and back-end application (task manager) with the use of an ASP.NET Web API. Other topics and projects include: application state, events, edit forms, and dependency injection.All those projects (and many others) present proper explanations, with excellent examples. The code of the projects is easy to follow, simple, and properly detailed. Therefore, you can use some of those projects as a base to develop your own applications.This is a totally recommended book if you want to learn Blazor WebAssembly in a practical way, with very useful examples, and short explanations. Congratulations to the author.
Amazon Verified review Amazon
Justin Horner Jul 15, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I love reading through example-focused books, and Blazor by Example is no exception! As the title states, this is a project-based guide to building web apps with .NET, Blazor WebAssembly, and C#.On your journey through learning Blazor by Example, you'll create several applications that scale up in complexity by chapter. Everything from creating your first Blazor application and making a weather app PWA to handling application state in a shopping cart experience gets covered throughout the projects in the book.I highly recommend this book to anyone interested in Blazor. It's a great learning resource and reference for Blazor WebAssembly projects.Here are a few of my chapter/topic highlights:- JS Interop- Building a Progressive Web App (PWA)- Using Application State- Building a Kanban Board using Events- Building a Task Manager using ASP.NET Web API
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela