In this article I will provide a short Hello World Tutorial using a small Sample Program example on how to use and develop applications in ASP.Net Core 8 for the first time.
This article makes use of Visual Studio 2022 for developing the ASP.Net Core 8 Hello World Tutorial with Sample Program example.
 
 
Creating a new ASP.Net Core 8 Project
Let’s get started with creating your first ASP.Net Core 8 Project.
1. Open Visual Studio and from Start section click on Create a new project.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
2. From the Create a new project Dialog window, select ASP.NET Core Empty option and then click on Next.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
3. Then, you can set a suitable Name for your project and also you can set its Location where you want to create the Project and then click on Next.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
4. From the ASP.NET Core Empty Dialog, select .NET 8.0 from Framework options and then click on Create.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
5. Your first Hello World ASP.Net Core Web Application Project is now ready and you should see the following folders and files in your Solution Explorer window.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
 
Adding Controller to the ASP.Net Core 8 Project
1. Inside the Solution Explorer window, Right Click on the Project and then click on Add and then click New Folder option from the Context Menu.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
2. Name the newly added Folder as Controllers.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
3. Now, inside the Solution Explorer window, Right Click on the Controllers folder and then click on Add and then click Controller option from the Context Menu.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
4. From the Add New Scaffolded Item Dialog window, select the “MVC Controller – Empty” option and then click on Add button.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
5. After adding the “MVC Controller – Empty” option you can provide a suitable Name to it and then click on Add button.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
Once you click on add, the following Controller is created. The default Action is “Index”.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
 
Adding View associated with the Controller to the ASP.Net Core 8 Project
1. Now you will need to Right Click inside the Controller class and click on Add View option in order to create a View for the Controller.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
2. From the Add New Scaffolded Item Dialog window, select the “Razor View” option and then click on Add button.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
3. You can provide a suitable Name to the View. This article does not use Layout Page and hence the “Use a layout page” CheckBox needs to be kept unchecked and then click on Add button.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
Once you click Add Button, the following View is created.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
 
Enabling MVC and Configuring the Routes
The last important part is to enable MVC and configure the Routes in the Program.cs file.
1. Open the Program.cs file from the Solution Explorer window.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
2. Inside the Program.cs, there are two configurations.
Configure MVC Services
Call the following function AddControllersWithViews which will instruct the program to add MVC Services.
Configure Routes
Then, the Route is set and the names of the Controller and the Action method are specified.
var builder = WebApplication.CreateBuilder(args);
 
//Enabling MVC
builder.Services.AddControllersWithViews();
var app = builder.Build();
 
//Configuring Routes
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
 
app.Run();
 
Finally, the Program.cs file will look as shown below.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
Now press F5 to run the Application and you should see a blank page in browser.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
 
Displaying a Message from Controller to View in ASP.Net Core 8 Project
1. Inside the HomeController’s Index Action method, a ViewBag property named “Message” is set.
public class HomeController : Controller
{
    public IActionResult Index()
    {
        ViewBag.Message = "This is my First MVC Core 8 App.";
        return View();
    }
}
 
2. The ViewBag property is displayed in the View named “Index” as shown below.
@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    @ViewBag.Message
</body>
</html>
 
3. Now press F5 to run the application and you should see a message displayed on page in browser.
ASP.Net Core 8: Hello World Tutorial with Sample Program example
 
 
Downloads


Other available versions