Skip to content
This repository was archived by the owner on Apr 20, 2019. It is now read-only.

Commit ba06f18

Browse files
MorneZaaymanguardrex
MorneZaayman
authored andcommitted
Data binding methods with parameters (#379)
1 parent 543b43d commit ba06f18

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

docs/components/index.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ description: Learn how to create and use Blazor components, the fundamental buil
55
manager: wpickett
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 12/25/2018
8+
ms.date: 01/29/2019
99
ms.prod: asp.net-core
1010
ms.technology: aspnet
1111
ms.topic: article
1212
uid: client-side/blazor/components/index
1313
---
1414
# Blazor components
1515

16-
By [Luke Latham](https://github.com/guardrex) and [Daniel Roth](https://github.com/danroth27)
16+
By [Luke Latham](https://github.com/guardrex), [Daniel Roth](https://github.com/danroth27), and [Morné Zaayman](https://github.com/MorneZaayman)
1717

1818
[!INCLUDE[](~/includes/blazor-preview-notice.md)]
1919

@@ -252,6 +252,32 @@ Lambda expressions can also be used:
252252
<button onclick="@(e => Console.WriteLine("Hello, world!"))">Say hello</button>
253253
```
254254

255+
It's often convenient to close over additional values, such as when iterating over a set of elements. The following example creates three buttons, each of which calls `UpdateHeading` passing an event argument (`UIMouseEventArgs`) and its button number (`buttonNumber`) when selected in the UI:
256+
257+
```cshtml
258+
<h2>@message</h2>
259+
260+
@for (var i = 1; i < 4; i++)
261+
{
262+
var buttonNumber = i;
263+
264+
<button class="btn btn-primary"
265+
onclick="@(e => UpdateHeading(e, buttonNumber))">
266+
Button #@i
267+
</button>
268+
}
269+
270+
@functions {
271+
string message = "Select a button to learn its position.";
272+
273+
void UpdateHeading(UIMouseEventArgs e, int buttonNumber)
274+
{
275+
message = $"You selected Button #{buttonNumber} at " +
276+
"mouse position: {e.ClientX} X {e.ClientY}.";
277+
}
278+
}
279+
```
280+
255281
## Capture references to components
256282

257283
Component references provide a way get a reference to a component instance so that you can issue commands to that instance, such as `Show` or `Reset`. To capture a component reference, add a `ref` attribute to the child component and then define a field with the same name and the same type as the child component.

0 commit comments

Comments
 (0)