MVC Sample Application - Part4

Adding First Controller:

           Now we will start handling requests by adding controllers.As we already studied Controllers are the C# classes that are derived from System.Web.Mvc.Controller.
             Now we will add controller by right click the Controllers folder in Solution Explorer and choose Add and then click Controller from the pop-up menu.

Adding Controller

                Then we will see a pop-up like following.

Controller Type

                After that choose Empty MVC Controller then click Add.Then name the controller type in following pop-up(Here I'm given FirstController as controller name) then click Add.

Controller Name

                  Then visual studio create a FirstController.cs class under Controller folder and a folder with controller name under Views folder.

Folder Structure

                  Visual Studio creates a default content in our controller like following.

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

namespace FirstMVCApplication.Controllers
{
    public class FirstController : Controller
    {
        //
        // GET: /First/
        public ActionResult Index()
        {
            return View();
        }
    }
}