Using MVC to Develop the Project (Cont.)


Controller (HomeController.cs)


C:\ASP.NET-workspace\HelloWorld\Controllers\HomeController.cs
 using System.Diagnostics;
 using HelloWorld.Models;
 using Microsoft.AspNetCore.Mvc;

 namespace HelloWorld.Controllers {
  public class HomeController: Controller {
   private readonly ILogger<HomeController> _logger;

   public HomeController( ILogger<HomeController> logger ) { _logger = logger; }

   public IActionResult Index( ) { return View( ); }

   public IActionResult Privacy( ) { return View( ); }

   [ ResponseCache( Duration = 0,
     Location = ResponseCacheLocation.None, NoStore = true ) ]
      
   public IActionResult Error( ) {
    return View( new ErrorViewModel { RequestId =
     Activity.Current?.Id ?? HttpContext.TraceIdentifier } );
   }
  }
 }
using System.Diagnostics;
The namespace provides classes that allow you to interact with system processes, event logs, and performance counters.

using HelloWorld.Models;
It is a directive that allows you to use classes defined within the Models folder of your project, assuming that folder contains your data models.

using Microsoft.AspNetCore.Mvc;
It provides types required to build an MVC app.

namespace
A namespace is a declarative region that provides a scope to the identifiers (names) such as variables, functions, classes, etc. It’s essentially a container that helps organize and prevent naming conflicts, especially in large projects. Think of it like a directory in a file system, where you can have files with the same name as long as they are in different directories.



      “My sister was with two men in one night...    
      she could hardly walk after that.    
      Can you imagine? Two dinners?    
      That’s a lot of food.”    
      — Sarah Silverman