Latest web development tutorials

ASP.NET MVC Controller

In order to learn ASP.NET MVC, we will build an Internet application.

Part 4: Add a Controller.

Controllers folder

Controllers folder contains is responsible for handling user input and response control classes.

MVC requires that all file name of the controller to "Controller" at the end.

In our example, Visual Web Developer has been created at the file: HomeController.cs (for Home page and About page) and AccountController.cs (for login page):


Web server will usually enter the URL request is mapped directly to a disk file on the server. For example: URL requests "" will be mapped directly to the root directory of the file server on the "index.php".

Mapping MVC framework is different. MVC is mapped to the URL method. These methods in a class called "controller."

The controller responsible for processing incoming requests, handling input, save data, and the response is sent back to the client.

Home Controller

In our application controller files HomeController.cs, we define two controls Index and About.

Replace the contents of the file into HomeController.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcDemo.Controllers
public class HomeController : Controller
public ActionResult Index()
{return View();}

public ActionResult About()
{return View();}

Controller view

Views folder and file Index.cshtml About.cshtml define the view controller ActionResult Index () and About ().