Hi everyone in this article I’m explaining about Controller class, how to add and how to work Controller class.
In my previous post I’ll intruduced about Start with ASP.NET MVC 4
The Controller Folder contains the controller classes responsible for handling user input and responses. Mvc requires name of all controllers to end with “controller”. The base class of all controllers is the ControllerBase which provides general mvc handling. The Controller class inherits from ControllerBase and is the default implement of a controller.
Let’s begin by creating a controller class. In Solution Explorer right click the controller folder and then click Add then Controller.
In the Add Controller dialog box, give name your new controller and select template Empty MVC Controller and then click Add
Solution Explorer that a new file has been created named “HomeController.cs” .
Now we have some changes in HomeController.cs file with fallowing changes.
public class HomeController : Controller
// GET: /Home/
public string Index()
return "Hi i am default action...";
public string Welcome()
return "This is welcome action...";
When run application first time then our default action return a string in html as an example. The Controller is named HomeController and the first method is name Index invoke by default.
If you want to call different action method then you pass url like this
ASP.NET MVC invokes different Controller class and different action name depending on the coming url. The default url routing set in RouteConfig.cs file. In my next post I will explain about URL Routing in MVC