Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Blazor Web Development Cookbook

You're reading from   Blazor Web Development Cookbook Tested recipes for advanced single-page application scenarios in .NET 9

Arrow left icon
Product type Paperback
Published in Nov 2024
Publisher Packt
ISBN-13 9781835460788
Length 282 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Pawel Bazyluk Pawel Bazyluk
Author Profile Icon Pawel Bazyluk
Pawel Bazyluk
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Chapter 1: Working with Component-Based Architecture 2. Chapter 2: Synchronous and Asynchronous Data Binding FREE CHAPTER 3. Chapter 3: Taking Control of Event Handling 4. Chapter 4: Enhancing Data Display with Grids 5. Chapter 5: Managing Application State 6. Chapter 6: Building Interactive Forms 7. Chapter 7: Validating User Input Forms 8. Chapter 8: Keeping the Application Secure 9. Chapter 9: Exploring Navigation and Routing 10. Chapter 10: Integrating with OpenAI 11. Index 12. Other Books You May Enjoy

Binding values with markup elements

In this recipe, we introduce the foundational concept of data binding in Blazor applications. This feature bridges the gap between the user interface and the application’s data or state. A deep understanding of this concept will allow you to level up the interactivity of your projects. We start with mastering the basics.

Let’s bind a simple text field to a backing variable to see the data flowing from the user interface to the backend.

Getting ready

Before you dive into binding, create a Recipe01 directory – this will be your working directory.

How to do it…

Follow these steps to bind a C# value with a markup element:

  1. Add a routable IntroduceYourself component that renders in an InteractiveWebAssembly mode:
    @page "/ch02r01"
    @rendermode InteractiveWebAssembly
  2. Inside the @code block of IntroduceYourself, initialize a User variable to store the user input value:
    @code {
       ...
You have been reading a chapter from
Blazor Web Development Cookbook
Published in: Nov 2024
Publisher: Packt
ISBN-13: 9781835460788
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image