Display Variables in ASP.NET Razor Pages

In this blog post, we will demonstrate how to print environment variables in an ASP.NET Razor Page.

In our previous blog post on ASP.NET, we demonstrated how to manage environment-specific settings in ASP.NET Core. We achieved this by configuring variables within an environment-specific file.

In this post, we will print an environment-specific variable called MyApp to an ASP.NET Razor page.


In the example below, I have configured my Razor Page Model with two properties: Greeting and Connectionstring. These properties hold and display data on the Razor page.

IndexModel.cshtml.cs (Page Model)

The Razor page below displays the Greeting property model using the @model syntax which gives us access to the properties of the model.

Index.cshtml (Razor View)

Leave a Comment

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