C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
ASP.NET MVC ControllerController is a class that handles user requests. It retrieves data from the Model and renders view as response. The ASP.NET MVC framework maps requested URLs to the classes that are referred to as controllers. Controller processes incoming requests, handle user input and interactions and executes appropriate business logic. The ControllerBase class is a base class for all controller classes. It provides general MVC handling. A controller mainly performs the following tasks.
Note: All controller classes must be named by using the "Controller" suffix.Create a ControllerWe can create controller for the application by adding a new item into the controller folder. Just right click on the controller folder and click add -> controller as given below. Providing controller name, then click Add. After adding this controller, as per the conventions project will create a folder with the same name as the controller name in the view folder to store the view files belongs to the controller. This controller contains the default code like below. // MusicStoreController.csusing System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcApplicationDemo.Controllers { public class MusicStoreController : Controller { // GET: MusicStrore public ActionResult Index() { return View(); } } } To access this controller to the browser, we are adding an index file to the MusicStore folder inside the view folder. This index file contains the following code. // index.cshtml<div class="jumbotron"> <h2>Welcome to the music store.</h2> </div> Run this file in non-debug mode by pressing Ctrl+F5. This will produce the following output.
Next TopicASP.NET MVC Actions
|