You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/mvc/views/razor.md
+16-2Lines changed: 16 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -261,9 +261,9 @@ Extra `@` characters in a Razor file can cause compiler errors at statements lat
261
261
262
262
### Conditional attribute rendering
263
263
264
-
Razor automatically omits attributes that aren't needed. If the value passed in is `null` or `false`, the attribute isn't rendered.
264
+
Razor automatically omits attributes that aren't required. If the value passed in is `null` or `false`, the attribute isn't rendered.
265
265
266
-
For example, consider the following razor:
266
+
For example, consider the following Razor markup:
267
267
268
268
```cshtml
269
269
<div class="@false">False</div>
@@ -289,6 +289,20 @@ The preceding Razor markup generates the following HTML:
289
289
<inputtype="checkbox"name="null">
290
290
```
291
291
292
+
Razor retains `data-` attributes if their values are `null` or `false`.
293
+
294
+
Consider the following Razor markup:
295
+
296
+
```cshtml
297
+
<div data-id="@null" data-active="@false"></div>
298
+
```
299
+
300
+
The preceding Razor markup generates the following HTML:
301
+
302
+
```html
303
+
<divdata-id=""data-active="False"></div>
304
+
```
305
+
292
306
## Control structures
293
307
294
308
Control structures are an extension of code blocks. All aspects of code blocks (transitioning to markup, inline C#) also apply to the following structures:
0 commit comments