Powered by Blogger.

Saturday, March 1, 2014

Asp.Net MVC4 Controller class example

In this post we will discuss how to add a controller class in Asp.Net MVC 4 application. Also if you have created a Asp.Net MVC 4 demo using this article, then you will able to see 2 default controllers are there: HomeController.cs and AccountController.cs.

Controllers are responsible for responding to user input, often making changes to the model in response to user input.

Here we will see how we can add a Controller class. Remember every controller class is  derived from System.Web.Mvc.Controller.

Also you can check out:

- Get control value using JavaScript with master page in Asp.Net:

- ValidationSummary in asp.net

- ValidationGroup example in Asp.Net

Follow below steps to add a controller class:

First Right click on the Controller folder then click on Add -> then click on Controller as shown in the figure below:

Then this will open the Add Controller dialog box. Thn give a controller name and select the template type, here we have selected Empty MVC Controller and then click on Add as shown in the figure below:

Now you can add a method like below in the controller class like below:
 public string WelCome()
            return "Welcome to MVC World !!!";

Now if you want to run like below

Then the output will show like below:
Welcome to MVC World !!!


Post a Comment