In this article we will know about Controller in ASP.NET MVC.
The Controller handles incoming URL requests. It is a class which is derived from base class System.Web.Mvc.Controller.
In MVC , every controller class name must end with word "Controller". Let say, controller for home page must be HomeController or contact controller must be ContactController.
The Controller handles incoming URL requests. It is a class which is derived from base class System.Web.Mvc.Controller.
In MVC , every controller class name must end with word "Controller". Let say, controller for home page must be HomeController or contact controller must be ContactController.
Creating an Empty ASP.NET MVC application
Now adding a new controller in MVC application.
In Visual Studio, right click on Controller folder - > select Add - > click on Controller.
After that it will open Add Scaffold dialog as shown
Select "MVC 5 Controller - Empty" and click add button after that it will open Add Controller dialog as shown
In Add Controller Dialog add a name like you want to create student controller then just replace "Default" with "Student" as shown
This will create "StudentController" as shown
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MVC_BasicTutorials.Controllers
{
public class StudentController : Controller
{
// GET: Student
public ActionResult Index()
{
return View();
}
}
}
In the next article we will learn about Action Method
Comments
Post a Comment