ASP.NET Core Razor Pages – Part 1

Introduction to Razor Pages

ASP.NET Core Razor Pages provide web developers with a way to create simple web applications (or web sites) using HTML, CSS, JavaScript, C# and the .NET library, but without the added complexity of the more powerful ASP.NET MVC framework. If you’ve used ASP.NET Web Forms, think of Razor Pages as an alternative that lets you just use standard HTML with helper code instead of dragging and dropping controls onto forms.

The pages you create will consist of a combination of regular old HTML, CSS, JavaScript and C#. But, wait!, you mght say, you can’t put C# in a web page because browsers only understand HTML, CSS, and JavaScript. You’re right. That’s why Razor Pages are rendered by an ASP.NET engine running on the server. The C# code is executed on the server and its output is combined with the rest of the mark-up and code on the page before being sent to a browser.

Microsoft introduced ASP.NET Web Pages with Razor syntax back in 2011. Since then, the framework has grown and matured. The latest version for “mainstream” ASP.NET is Web Pages 3.2.3. The new cross-platform version of .NET, .NET Core,  includes Razor Pages, which is essentially the same as Web Pages, but they behave a little differently.

Learning to Develop with Razor Pages

Microsoft has published a very nice set of tutorials for developing ASP.NET Web Pages, but it was written for “mainstream” ASP.NET Web Pages, not the .NET Core Razor Pages. There isn’t really a good set of tutorials for Razor Pages yet. So, in this series of posts I’ll discuss each of the lessons in the old Web Pages tutorials and give you the updated instruction you need to make the lesson work for Razor Pages in .NET Core 2.0.

I’ll be using Visual Studio 2017 (avialabe free for Mac OS and Windows), but you could also use Visual Studio Code (available free for Mac OS, Linux and Windows), or any other code editor for that matter. If are using a code editor, instead of the full-blown Visual studio 2017, then you’ll want to read about using the .NET Core Command Line Interface

Getting Started

Let’s take a look at the first lesson, Getting Started. The introductory information in this lesson is still valid (except the part about Web Matrix), but the installation instructions are not. Instead of Web Matrix, you will want to install the .NET Core 2.0 SDK and runtime as well as Visual studio or your own favorite code editor. We’ll skip  the sections “Install Everything”, through “Testing the Page”, and instead we’ll create a Web Pages project as described in Getting started with Razor Pages (just this one page, don’t go on to “Adding a Model”).

Once you’ve created a new project, you’ll want to remove the pages that were added to the app by default. Remove all of the files from the Pages folder. Now you can add your own page. Right-click on the Pages folder, click add, click on new file, in the left pane of the new file dialog, select ASP.NET core, on the right, click Razor page.

Next, pick up with the section, Adding Some Server-Side Code. This still works! Just make sure you have the @Page directive at the top of the page. When you run the project, a browser will be launched and the current date and time will be displayed:

Right now it’s 09/30/2017 14:51:44

The code for this tutorial is available here:

In Part 2, we will do the lesson on Programming Basics


September 30, 2017 at 3:10 pm Leave a comment

Women in Agile: The Changing Face of Agile – Session Notes

In this post, I will share my notes on a presentation about Women in Agile given for the Agile Alliance.


In this video, Natalie Warnert, the chair of Agile Alliance’s Women in Agile Initiative, explains the background behind the program. Then Cindy Morse, VP of Engineering Operations at Salesforce Marketing Cloud discusses her involvement and experiences in the greater technology community. This workshop is part of the Women in Agile Initiative.
– Description from the Agile Alliance web page.

October 11, 2016 at 2:13 pm Leave a comment

Visual Studio Code: Use, Build, Improve


An Open-Source Project

In a previous post, I mentioned that I plan to participate in an open-source project as part of my sabbatical activities. After looking at quite a few projects, I found one that I believe will give me the experience I want- which is to get firsthand understanding of software development work-flow and practices in an open-source project.

A Cross-Platform Code Editor

The project is Visual Studio Code. VS Code is a lightweight, cross-platform, coding editor that supports plug-ins. It’s not an IDE, although with the right plug-ins it can give you all the power of a modern IDE. It is very similar to Sublime Text or Atom. In fact, it is built on Electron, the same framework used by Atom.  (Electron is a  framework for building desktop apps with HTML, CSS, and JavaScript.) (more…)

October 8, 2016 at 6:01 am Leave a comment

Open Source Machine Translation Projects

Why I want to contribute to an open-source project

I’m looking for an open source projects for machine translation of natural languages that I can contribute to. My motivation comes partly from my sabbatical project– one part of the project is to manage an open source project. No, I’m not looking for a project to take over. I just want to get some experience as a contributor before I manage a project. Another part of my motivation comes from my long-term interest in linguistics and translation- my master’s degree is in Linguistics. And, I’ve started getting sucked in by the exciting stuff happening now in machine leaning. (more…)

October 7, 2016 at 10:30 am 1 comment

Agile Sabbatical

I am currently on sabbatical from Lane Community College studying the current “best practices” in Agile software development as they are being applied in the local software industry. I am conducting this study by:

  • Reading current literature on Agile methodologies
  • Visiting software development teams at local companies to do observation and interviews
  • Applying what I learn to managing a software development team on an Open Source software project


October 6, 2016 at 2:55 pm 2 comments

Is It possible to run a 100% Remote Team?

At QCon 2015, in SanFrancisco, Jeremy Edberg gave a presentation on remote teams. In this post I will summarize what he said about the pitfalls they’ve run into at his company, the parts that are working well, and a summary of their research talking to other fully or partially remote teams. (more…)

October 6, 2016 at 1:55 pm Leave a comment

Using the Android Fused Location Provider

location-clipart-map_pinIn this post, I’ll walk you through the code in a very minimal app that just demonstrates getting locaiton. This app was created using the Xamarin Android platform, so it is written in C# but still uses the Fused Location Provider API which is provided by Google Play Services . My code is available on GitHub in a Xamarin Studio / Visual Studio solution: Geolocation Demo. (more…)

May 27, 2016 at 2:29 pm 2 comments

Older Posts

Bird’s Bits

Computers, software & the Internet

Recent Posts

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 37 other followers