This article provides an advanced overview of ASP. net mvc models, views, and controllers. In other words, it explains "M" "V" "C" in ASP. net mvc ". After reading this article, you should understand ASP.. Net MVC, you should also know how ASP. net MVC application and ASP.. NET web form applications.
When an ASP. NET application is started for the first time, application_start () is called () Method In listing 1, this method is called the registerroutes () method, and the registerroutes () method creates the default route table.
The default route table has only one route Record It divides all inbound requests into three sections. The first section maps to the Controller name, the second section maps to the behavior name, and the last section maps to the parameter ID passed to the behavior.
URL:
/Product/details/3
This URL is parsed into the following three parts:
Controller = productcontroller
Action = Details
Id = 3
Note that the suffix "controller" is at the end of the controller parameter, which is just a quirk of MVC.
The default route includes the default values. The default controller is homecontroller and the default behavior is index. The default ID is an empty string, Thoughts How to resolve the following URL in response:
/Employee
This URL is parsed into the following three paragraphs:
Controller = homecontroller
Action = index
Id = ""
The request is routed to the index () behavior of the homecontroller class.
Understanding Controller
Controller controls users and ASP. NET MVC Applications The interaction method is determined by the Controller to return content to the user who sent the request.
The controller is a class. The ASP. net mvc sample application only contains a controller named homecontroller. VB in the Controller folder. The contents of homecontroller. VB are shown in List 2.
Listing 2 homecontroller. VB
Public Class HomeController
Inherits System.Web.Mvc.Controller
Function Index()
ViewData("Title") = "Home Page"
ViewData("Message") = "Welcome to ASP.NET MVC!"
Return View()
End Function
Function About()
ViewData("Title") = "About Page"
Return View()
End Function
End Class