From the course: Learning ASP.NET Core MVC
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Render dynamic content with Razor
From the course: Learning ASP.NET Core MVC
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Render HTML with Razor3m 51s
-
(Locked)
Render dynamic content with Razor5m 1s
-
(Locked)
Reuse shared HTML markup with layouts3m 7s
-
(Locked)
Rendering reusable sections of content in a layout2m 34s
-
(Locked)
Pass data from the controller to the view1m 56s
-
(Locked)
Render data with strongly typed views2m 16s
-
-
-
-
-