From the course: Learning ASP.NET Core MVC

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Render dynamic content with Razor

Render dynamic content with Razor

From the course: Learning ASP.NET Core MVC

Start my 1-month free trial

Render dynamic content with Razor

- [Instructor] Converting static HTML files to Razor files is just the first step in creating a dynamic web application. It's the ability to write C# code right within Views that makes Razor so useful, and in this video, I'll show you the basics of the Razor syntax. At a glance, there's not really much to the Razor syntax. For most scenarios, all you need to do is type the @ character anywhere in the page, immediately followed by the C# code that you want to execute and render. For example, let's say that I want to add a copyright to my page, and make sure that it always emits the current year, so that I don't have to remember to update it all the time. I can just do this. Notice how I get full intellisense when I begin writing code after the @ sign. Now when I run this page and scroll to the bottom, I can see that Razor has evaluated that expression, and rendered the resulting value as text right into the page. That's a pretty simple example, but the real power of Razor lies in HTML…

Contents