I want write "Hello World" with ASP.NET Core.

Abdurrahman KAYA 40 Reputation points
2024-04-06T09:13:16.2333333+00:00

I want write "Hello World" with ASP.NET Core. Can you help me?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,180 questions
0 comments No comments
{count} votes

Accepted answer
  1. Marcin Policht 10,845 Reputation points MVP
    2024-04-06T10:11:13.8866667+00:00
    1. Create a New ASP.NET Core Web Application: Open Visual Studio and create a new project. Select "ASP.NET Core Web Application" from the available project types.
    2. Choose ASP.NET Core Template: In the project creation wizard, select the ASP.NET Core template. You can choose either ASP.NET Core MVC or ASP.NET Core Razor Pages, depending on your preference.
    3. Configure the Project: Configure the project settings such as the project name, solution name, and location. Click "Create" to generate the project files.
    4. Write the "Hello World" Code: Open the HomeController.cs file (for MVC) or Index.cshtml.cs file (for Razor Pages) in the Controllers or Pages folder, respectively. Write the following code to display "Hello World":

    For MVC

    using Microsoft.AspNetCore.Mvc;
    
    namespace YourNamespace.Controllers
    {
        public class HomeController : Controller
        {
            public IActionResult Index()
            {
                return Content("Hello World");
            }
        }
    }
    
    

    For Razor Pages:

    using Microsoft.AspNetCore.Mvc.RazorPages;
    
    namespace YourNamespace.Pages
    {
        public class IndexModel : PageModel
        {
            public void OnGet()
            {
                ViewData["Message"] = "Hello World";
            }
        }
    }
    
    
    1. Run the Application: Press F5 or click on the "Play" button in Visual Studio to build and run the application. Open a web browser and navigate to the URL displayed in the output window. You should see "Hello World" displayed on the webpage.

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful