Razor is the dotnet templating language, Razor is the syntax used to create views in dotnet applications. It will normally be found in `.cshtml` files. You can think of it in a similar way to JSX, in that Razor is to C#, what JSX is to Javascript in a React application.
Templating languages don’t transform data, but arrange it for display in a view.
Example displaying a list in JSX:
const list = (items) => {
return (
<ul>
{items.map((item, index) => (
<li key={item}>{item}</li>
))}
</ul>
);
}
Displaying the same list in Razor
<ul>
@foreach(var item in items) {
<li>@item</li>
}
</ul>
Further Reading
A great cheatsheet for copy + paste
https://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/
A good abstract overview of templating engines as a whole:
https://thomaslevine.com/computing/templating-languages/
The Microsoft ASP.net Razor Guide
Comments
Add your comment