How to Comment Code in ASP.NET Core Razor Pages

You’ve been coding for a while and want to get better at it. You know that you should be commenting on your code, but how do you go about doing so? It’s not easy, but with this blog post, we hope to help.

This blog post will show you how to add comments to ASP.NET Core Razor pages. In the below code section, you can see how to add a single line comment to a razor page.

<!-- Comments go here -->
@{ List<string> mylist = new List<string>(){"Ansible", "Terraform", "Git"};  }

We can also have multiple lines of code on our razor page, as shown below.

<!-- Single line
     Add some more code here
     And here
 -->

ASP.NET Core Razor Pages

Razor Pages in ASP.NET Core provide a page-based programming model for building web applications. The Razor Page Model separates the page content from the code that drives it. This allows you to edit either without affecting the other, and it provides a clean separation that helps developers create readable code with reduced duplication. It consists of .cshtml markup views, code-behind files containing C# or VB.NET code that implements the logic behind the page’s markup, and a Razor Class (.cs) file representing the backing model for the page.

The Razor Pages is closely related to ASP.NET MVC Views, offering similar functionality with Web Pages or WebForms.

The Razor Pages is designed to build HTTP services for web applications intended to use an HTTP GET method exclusively. Each URL of the application maps directly to an action. The Razor page model offers several features over plain HTML markups: code separation, strong typing and templating offered by the Razor language.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.