I am learning server-side. Blazor .
I have read the code of some projects and found some that use:
@{
}
and some that use:
@code{
}
and others that use:
@function{
}
to mark the code block.
I would like to know the difference between these. Thank you.
Razor is a templating engine that combines C# with HTML to build dynamic web content. Blazor is a component-based, single-page app framework for building client-side web apps using . NET that works well with all modern browsers via WebAssembly for client-side Blazor.
Razor is a markup syntax that lets you embed server-based code (Visual Basic and C#) into web pages. Server-based code can create dynamic web content on the fly, while a web page is written to the browser.
The Razor syntax gives you all the power of ASP.NET, but is using a simplified syntax that's easier to learn if you're a beginner, and makes you more productive if you're an expert. Razor web pages can be described as HTML pages with two kinds of content: HTML content and Razor code.
Blazor apps are built using Razor components, informally known as Blazor components. A component is a self-contained portion of user interface (UI) with processing logic to enable dynamic behavior. Components can be nested, reused, shared among projects, and used in MVC and Razor Pages apps.
@
for directive(s)
@code{ }
[2] should be used. @function{ }
[3] is still effect, in case of method, not recommended in current version.
[2] https://docs.microsoft.com/vi-vn/aspnet/core/mvc/views/razor?view=aspnetcore-3.0#code
[3] https://docs.microsoft.com/vi-vn/aspnet/core/mvc/views/razor?view=aspnetcore-3.0#functions
See document for all cases https://docs.microsoft.com/vi-vn/aspnet/core/mvc/views/razor?view=aspnetcore-3.0#functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With