From the course: Learning ASP.NET Core: MVC, Razor Pages, Web APIs & Other Foundations
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Using Razor syntax
From the course: Learning ASP.NET Core: MVC, Razor Pages, Web APIs & Other Foundations
Using Razor syntax
- [Instructor] Razor syntax allows you to embed entire C# code blocks in your pages, as well as simple C# expressions that will be evaluated and rendered as HTML before being sent back to the browser. This default index page we looked at in the last movie already has a C# code block in it just after the page and Model directives. On line three, you can see the @ sign followed by a pair of curly braces. That's a C# code block. I can write just about any C# code I want inside those curly braces. Currently, it contains just one line of code that assigns a value to an element in the special ViewData array. ViewData is a property that exists on all views such as this razor page. It's a simple weekly typed dictionary that is a convenient place to store small bits of data you might need on your page. You access values in the dictionary using string keys. This line of code assigns the string "Home page" to the key named "Title." Let's imagine I want to store a welcome message in the ViewData…
Contents
-
-
-
-
Understanding Razor Pages5m 7s
-
(Locked)
Using Razor syntax9m 17s
-
(Locked)
Implementing page layouts10m 32s
-
(Locked)
Routing to pages8m 18s
-
(Locked)
Creating links with tag helpers6m 41s
-
(Locked)
Binding to data6m 11s
-
(Locked)
Challenge: Create a Razor Pages application1m 31s
-
(Locked)
Solution: Create a Razor Pages application5m 4s
-
-
-
-
-
-
-