MVC - Understanding Model, View, Controller (MVC)

by
Jeremy Canfield |
Updated: March 20 2020
| MVC articles
CONTROLLER
In Solution Explorer, expand Controllers, and select HomeController.cs Following is an sample HomeController.cs file for example.com. This controller will produce 3 pages:
- www.example.com/Home/Index
- www.example.com/Home/About
- www.example.com/Home/Contact
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace example.com.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
return View();
}
public ActionResult Contact()
{
return View();
}
}
}
VIEW
In Solution Explorer, expand View > Home, and there will be 3 razor objects:
- Index.cshtml
- About.cshtml
- Contact.cshtml
By default, the "About" view will likely contain the following markup:
@{
ViewBag.Title = "About";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
With the following markup, the "About" page would look like this:
Even if you remove all of the markup from the "About" view, www.example.com/Home/About will still produce the following.The content displayed comes from the _Layout.cshtml and _LoginPartial.cshtml files under /View/Shared.
Did you find this article helpful?
If so, consider buying me a coffee over at