When an MVC action calls View, the Razor view engine searches for a .cshtml file matching the action name. It first checks the controller-specific Views folder, then Views/Shared for reusable views. section 21.2.2
HomeController.Index
An Index action on Home returns View(product). The convention searches Views/Home/Index.cshtml first, then Views/Shared/Index.cshtml. The controller name contributes Home after removing the Controller suffix. section 21.2.2
Listing 21.5 The contents of the HomeController.cs file in the Controllers folder
using Microsoft.AspNetCore.Mvc;
using WebApp.Models;
namespace WebApp.Controllers {
public class HomeController : Controller {
private DataContext context;
public HomeController(DataContext ctx) {
context = ctx;
}
public async Task<IActionResult> Index(long id = 1) {
return View(await context.Products.FindAsync(id));
}
}
}
Inspect the controller action that retrieves a product and returns it through View, triggering conventional view lookup. section 21.2.2
