4,815 questions
- 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.
- 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.
- Configure the Project: Configure the project settings such as the project name, solution name, and location. Click "Create" to generate the project files.
- Write the "Hello World" Code: Open the
HomeController.cs
file (for MVC) orIndex.cshtml.cs
file (for Razor Pages) in theControllers
orPages
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";
}
}
}
- 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