Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpmorris committed May 23, 2024
2 parents dc3bec3 + cce0b7d commit 33b2d45
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Razor will only execute C# code in the following places:
3. Within the `@code` section.

The technique we need to employ to generate one or more attributes + values for a HTML element is called "Attribute splatting".
Attribute splatting involves assigning a `Dictionary<string, object>` to an attribute with the special name `@attribute`.
Attribute splatting involves assigning a `Dictionary<string, object>` to an attribute with the special name `@attributes`.

```razor
<div @attributes=MyCodeGeneratedAttributes/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ then adjusting the position of `@attributes=` in our `ChildComponent` will give
<div
first="consumer-value-1"
second="consumer-value-2"
inserted="consumer-inserted-value />
inserted="consumer-inserted-value" />
```

## R.I.P. default values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IChatService
```

To implement this service we'll use a `List<string>` to store the chat history,
and remove messages from the start of the list whenever there are more than 100 in the queue.
and remove messages from the start of the list whenever there are more than 50 in the queue.
We'll use the `lock()` statement to ensure thread safety.

```razor {: .line-numbers}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IMyTransientService

To implement this interface we'll write a class with a `static` integer field that we can use to determine the next
available sequence number.
This field will be marked as `[volatile](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile)`
This field will be marked as [`volatile`](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile)
and altered using `System.Threading.Interlocked.Increment` so we can modify the field across multiple threads without
having to do any thread locking.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ order: 3
[![](images/SourceLink.png)](https://github.com/mrpmorris/blazor-university/tree/master/src/Forms/ValidatingUserInput)

The `DataAnnotationsValidator` is the standard validator type in Blazor.
Adding this component within an `EditForm` component will enable form validation based on .NET attributes descended
Adding this component within an `EditForm` component will enable form validation based on .NET attributes descended
from `System.ComponentModel.DataAnnotations.ValidationAttribute`.

First we'll create a short example, then we'll go through what happens behind the scenes.
Expand Down Expand Up @@ -133,4 +133,4 @@ whereas the razor expression makes it more obvious to other developers that we a
}
```

[![](images/ValidationSummaryAndValidationMessages.png)](http://blazor-university.com/wp-content/uploads/2019/08/ValidationSummaryAndValidationMessages.png)
[![](images/ValidationSummaryAndValidationMessages.png)](images/ValidationSummaryAndValidationMessages.png)
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ This is the problem we will solve using JavaScript Interop, `@ref`, and `Element
- First create a new Blazor application.
- In each of the pages replace the content with the same mark-up just below each `@page` directive.

```html
Enter your name: <input autofocus />
```

Run the application and observe how the `<input>` element does not automatically gain focus, not even on first page load.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Blazor layouts work only within the part of the HTML that Blazor is defined with
in a default Blazor application this is everything within the `<app>` element.
It isn't currently possible to alter attributes of HTML elements outside of this scope except by use of [JavaScript Interop](http://blazor-university.com/javascript-interop/).

[![](images/Layout.png)](http://blazor-university.com/wp-content/uploads/2019/06/image.png)
[![](images/Layout.png)](images/Layout.png)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The name Blazor is a combination/mutation of the words Browser and Razor (the .N
The implication being that instead of having to execute Razor views on the server in order to present HTML to the browser,
Blazor is capable of executing these views on the client.

[![Blazor client side](images/BlazorClientSide-300x251.png)](http://blazor-university.com/wp-content/uploads/2019/05/BlazorClientSide.png)
[![Blazor client side](images/BlazorClientSide-300x251.png)](images/BlazorClientSide-300x251.png)

Blazor app with client-side execution

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ We'll also add a `[Parameter]` property, expecting an `IEnumerable<TItem>`.
[Parameter]
public IEnumerable<TItem> Data { get; set; }
}
```

## Using the generic component

Create a `Person` class with three properties.

```cs
public class Person
{
public string Salutation { get; set; }
Expand Down

0 comments on commit 33b2d45

Please sign in to comment.