ASP.NET MVC Controllers Overview:
Controllers are inherited from System.Web.Mvc.Controller. Controllers in ASP.NET MVC framework are the starting point. Controllers are the first to receive the request when the web application sends a HTTP requests. It decides which model will react and presented, after which the view is rendered.
Each method in controllers are known as action method. You can invoke it from the method name itself.
Now, we will create a new Controller. For this, we will create a new ASP.NET MVC empty web application.
Creating a empty ASP.NET MVC web application :
Step 1 : Select File > New > Project :
Step 2 : Name the application as MyMvcApplication
Step 3 : Select as Empty website.
Step 4 : Creating a Controller.
After creating the application, visual studio will create all the necessary folders and other stuff which are essential for our MVC application. To create a new Controller, click on Controllers > Add > Controller and name the Controller as HomeController.
Step 5 : Editing our controller.
After creation, a basic code will be present by default in HomeController.cs.
Edit the HomeController.cs as below :
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MyMvcApplication.Controllers { public class HomeController : Controller { // // GET: /Home/ public String Index() { return "Hello, I'm a simple ASP.NET MVC CONTROLLER."; } } }
We will be showing a simple string message when this method is called. Now run the web application.
Next section on ASP.NET MVC Actions
Pingback: ASP.NET MVC Actions Example • ParallelCodes;
Pingback: ASP.NET MVC Tutorial • ParallelCodes;