WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

ASP.NET MVC - Controllers


To learn ASP.NET MVC, we are Building an Internet Application.

Part IV: Adding a Controller.


The Controllers Folder

The Controllers Folder contains the controller classes in charge of taking care of client input and responses.

MVC requires the name of all controllers to finish with "Controller".

In our precedent, Visual Web Developer has made the accompanying documents: HomeController.cs (for the Home and About pages) and AccountController.cs (For the Log On pages):

Controllers

Web servers will typically outline URL asks for specifically to circle documents on the server. For instance: a URL ask for like "http://www.welookups.com/default.asp" will outline to the record "default.asp" at the root index of the server.

The MVC structure maps in an unexpected way. MVC maps URLs to techniques. These strategies are in classes called "Controllers".

Controllers are in charge of preparing approaching solicitations, dealing with info, sparing information, and sending a reaction to send back to the client.


The Home controller

The controller document in our application HomeController.cs, characterizes the two controls Index and About.

Swap the substance of the HomeController.cs document with this:

utilizing System;
utilizing System.Collections.Generic;
utilizing System.Linq;
utilizing System.Web;
utilizing System.Web.Mvc;

namespace MvcDemo.Controllers
{
public class HomeController : Controller
{
open ActionResult Index()
{return View();}

public ActionResult About()
{return View();}
}
}

The Controller Views

The records Index.cshtml and About.cshtml in the Views organizer characterizes the ActionResult sees Index() and About() in the controller.