(C# ASP.NET Core) Practice Exercises and Questions on Razor Pages

(LEVEL IS BEGINNERS) Following is a collection of exercises and practice questions that help in cementing the concepts of asp.net core razor pages. Solve them and join our course for their solutions.
(Rev. 19-Mar-2024)

Categories | About |     |  

Parveen,

Table of Contents (top down ↓)

COMMERCIAL USE OF THIS CONTENT IS NOT ALLOWED

Exercises on Razor Pages

for solutions please join our Course on ASP.NET Core with Project ("Find a Doctor")
  1. Create an application consisting of a razor page called Index - but without its backing csharp file. The razor page should print your name.
  2. Display your name thus: Add a string variable called strName to the page in Ex 1. Set the variable to your name. Then display the variable strName.

  3. Create an application consisting of a razor page called Index - but without its backing csharp file. Create two int variables i and j. Set i to 7 and j to 2. Display their sum using razor syntax.

  4. Add a function called, say, GetName to the razor page in the first exercise. The function has a return type of String and returns your name. Now display your name by calling the above function.

  5. Create an application consisting of a razor page called Index and its backing csharp file. Create two int properties i and j in the backing class. Set i to 7 and j to 2. Display their sum using razor syntax.

Exercises on Middleware

for solutions please join our Course on ASP.NET Core with Project ("Find a Doctor")
  1. Without using razor pages, write a simple ASP.NET Core application that writes a "Hello World!" message to the response stream when an HTTP GET request is made to the home page of your website.

  2. Without using razor pages, write a simple ASP.NET Core application that sends a FORM consisting of an input textbox and a submit when an HTTP GET request is made to the home page of your website. The application should handle the posted data and respond by sending back the upper case equivalent of the input typed by the user.

Exercises on Layout, CSS Integration and Inter-page linking

for solutions please join our Course on ASP.NET Core with Project ("Find a Doctor")
  1. Create an application with a layout file [full head, body html tags] that shows the current system time in a h1 tag. The file connects to a CSS file called "mycss.css", which is placed in a wwwroot directory, and has a class for a p tag that sets its text color to red. Create a razor page called index that shows your name in a "p" tag. This page should merge into the layout file. Run the app to verify that your name appears in red.

  2. Many CSS frameworks like bootstrap are available on the internet. Find any framework of your choice and create a layout file [full head, body, html, etc.,] by linking its CSS/JS files. Then create two pages - Index and Products. Each page has the same two buttons called "Home" and "Products". When Home is clicked the user should be taken to the Index page, and when Products is clicked the user should be taken to the Products page.


This Blog Post/Article "(C# ASP.NET Core) Practice Exercises and Questions on Razor Pages" by Parveen is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.