tailieunhanh - Visual studio 2010 part 28

Microsoft Visual Studio 2010: TIP Hướng dẫn của một người mới bắt đầu Bạn có thể thay đổi số cổng VS máy chủ web của bạn. Nếu bạn mở trang thuộc dự án của bạn bằng cách chuột phải bấm vào các dự án trong Solution Explorer và chọn Properties, sau đó chọn tab Web bên trái, theo máy chủ, bạn có thể chỉ định một cổng cụ thể hoặc có những lựa chọn máy chủ Web khác. | 256 Microsoft Visual Studio 2010 A Beginner s Guide TIP You can change your VS Web server s port number. If you open your project s property page by right-mouse clicking on the project in Solution Explorer and select Properties then select the Web tab on the left under Servers you can specify a specific port or make other Web server choices. For MVC the important part of the URL is Home About. Home is the name of the Controller and MVC appends Controller to the URL name looking for the HomeController class shown in Listing 9-1 physically located in the Controller folder which is why it s important to ensure you create files in the proper locations. About is an action which corresponds to the About method shown in Listing 9-1. Similar to the About method the Index action is run through the following URL http localhost 1042 Home Index In a later section of this chapter you ll learn how MVC performs routing which maps URLs to Controllers. Both the Index and About actions in Listing 9-1 invoke a method named View. This is a convention for invoking a View with the same name as the action method. For example calling View in the Index action will show a View named Index and the call to View in the About method will show a View named About. One more item to point out is how the Index action assigns a string to a collection called ViewData. The ViewData collection is one way for a Controller to pass Model data to a View. I ll cover more on Controllers including how to create your own in a later part of this chapter but now let s do a quick review of Views so that you can see what happens when they are invoked by the Controller. Displaying Views A View is what displays in the browser and allows interaction with the user. The View can display any information that a Controller passes to it. For example notice that the Index action in Listing 9-1 assigns a string Welcome to MVC with the Message key in the ViewData collection. Looking Inside a .