Chapter 9: Creating Web Applications with ASP.NET MVC

255

return View();

}

public ActionResult About()

{

return View();

}

}

}

VB:

<HandleError()> _

Public Class HomeController Inherits System.Web.Mvc.Controller

Function Index() As ActionResult

ViewData("Message") = "Welcome to ASP.NET MVC!"

Return View()

End Function

Function About() As ActionResult

Return View()

End Function

End Class

Listing 9-1 demonstrates how closely ASP.NET MVC is tied to conventions. Notice that the class name is HomeController. Appending Controller to a class name is a convention that ASP.NET MVC uses to identify which classes are controllers. Also, the methods in the class are referred to as Actions in ASP.NET MVC. Using the Controllers folder for a Controller, appending the class name with Controller, and available actions are all conventions that you must follow. The following URL, a browser address, demonstrates how these conventions support routing to find a Controller and invoke the About action. You can see this URL if you run the application and click the About tab:

http://localhost:1042/Home/About

The http://localhost:1042 part of the URL is a Web server that is built into VS and runs the Web application without needing a Web server such as Internet Information Server (IIS). The number 1042 is a random port number generated by the Web server, and your port number is likely to be different.

Page 278
Image 278
Microsoft 9GD00001 manual 255