Common Blazor Templates
- 2 minutes to read
This topic describes templates for Blazor that you can expand in .razor markup.
For example, you can type bht and press Tab (or Space, depending on your settings) to create a Blazor component with an HTTP call.
The LifeCycle Methods section lists templates that you can expand in the @code section inside .razor files.
Important
Visual Studio Intelli
#Components
Template | Description |
---|---|
bch | Creates a child component with a parameter. |
bcmp | Creates a blank component. |
bht | Creates a component with an HTTP call. |
cv | Creates a <Cascading |
dav | Creates a <Data |
ef | Creates an <Edit |
#Input
Template | Description |
---|---|
icb | Creates an <Input |
idt | Creates an <Input |
in | Creates an <Input |
it | Creates an <Input |
ita | Creates an <Input |
isel | Creates an <Input |
#Blazor Directives
Template | Description |
---|---|
ba, battr | Creates an @attribute directive. |
bc, bcode | Creates a Blazor @code block. |
bf, bfunc | Creates a Blazor @functions block. |
bh | Creates an @inherits directive. |
bj | Creates an @inject directive. |
bjc | Creates an @inject IConfiguration configuration. |
bjh | Creates an @inject Http |
bl | Creates a @layout directive. |
bm | Creates a @model directive. |
bp | Creates a @page “/“ with a route. |
#Conditionals and Control Statements
Template | Description |
---|---|
do, dw | Creates a @do (do/while) control statement. |
fe | Creates a @foreach control statement. |
for, fri, frj | Creates a @for control statement. |
if | Creates an @if conditional. |
ife, ifl | Creates an @if @else conditional. |
sw | Creates a @switch conditional. |
tc | Creates a @try/catch block. |
tcf | Creates a @try/catch/finally block. |
tf | Creates a @try/finally block. |
u | Creates a @using statement. |
wh, while | Creates a @while control statement. |
#Lifecycle Methods
Note
Visual Studio 2022 does not support lifecycle methods.
The following lifecycle method overrides work inside the @code section of .razor files:
Template | Description |
---|---|
oar | Creates an On |
oar, | Creates an On |
oi | Creates an On |
oi, | Creates an On |
onch | Creates an On |
onch, | Creates an On |
ops | Creates an On |
ops, | Creates an On |
sr, sr, | Creates a Should |
A comma at the end of a lifecycle method override template generates a synchronous version of the event.