Reputation: 59
While trying to learn about ASP.NET MVC and Razor, i found 3 types of .cshtml files. Some accept Razor code like @Page, some do not.
Please help me understand what these 3 types of file mean:
.cshtml with green @ symbol
.cshtml with green @ symbol and .cshtml.cs code behind
.cshtml with white [@] symbol
Thank you!
Upvotes: 0
Views: 270
Reputation: 32069
.cshtml
with green @
symbol - Newly introduced ASP.NET Core Razor
Page.cshtml
with green @
symbol and .cshtml.cs
code behind -Newly
introduced ASP.NET Core Razor Page with Model.cshtml
with white [@]
symbol- Traditional ASP.NET MVC Razor ViewFor more details: Razor Pages in ASP.NET Core
Upvotes: 1
Reputation: 489
What you're seeing in your first example is a .cshtml View
excerpt from asp.net docs: https://learn.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/views/asp-net-mvc-views-overview-cs
For ASP.NET or Active Server Pages, ASP.NET MVC does not include anything that directly corresponds to a page. In an ASP.NET MVC application, there is not a page on disk that corresponds to the path in the URL that you type into the address bar of your browser. The closest thing to a page in an ASP.NET MVC application is something called a view.
In an ASP.NET MVC application, incoming browser requests are mapped to controller actions. A controller action might return a view.
What you're seeing in your first example is a Razor Pages project
excerpt from MSDN Magazine: https://msdn.microsoft.com/en-us/magazine/mt842512.aspx
Where Razor Pages shine is in encapsulating and grouping UI details. Razor Pages support inline or separate class-based page models, which can represent data elements the page will display or manipulate. They also support handlers that eliminate the need for separate controllers and action methods. These features greatly reduce the number of separate folders and files required to work with a given page on a Web app.
Upvotes: 1