4. Add Controller
Step 1: Select the EXPLORER icon and then control-click (right-click) Controllers > New File and name the new file HelloWorldController.cs
.

Step 2: Replace the contents of Controllers/HelloWorldController.cs
with the following code:
using Microsoft.AspNetCore.Mvc;
using System.Text.Encodings.Web;
namespace MvcMovie.Controllers
{
public class HelloWorldController : Controller
{
//
// GET: /HelloWorld/
public string Index()
{
return "This is my default action...";
}
//
// GET: /HelloWorld/Welcome/
public string Welcome()
{
return "This is the Welcome action method...";
}
}
}
Output
Append "HelloWorld" to the path in the address bar. The Index
method returns a string.

Step 3: Browse to: https://localhost:5001/HelloWorld/Welcome
.

Last updated