Bài giảng Lập trình web: View - Nguyễn Hà Giang

After reading the material in this chapter, you should be able to: Define and describe views, explain and describe the razor engine, define and describe the HTML helper methods. | View Nguyen Ha Giang 1 Objectives Define and describe views Explain and describe the razor engine Define and describe the HTML helper methods 2 Working with Views To display HTML content to the user, you can instruct the controller in the app to return a view. A View Provides the UI of the app to the user Is used to display content of an app and also to accept user inputs Uses model data to create this UI Contains both HTML markup and code that runs on the Web server 3 View Engines Are part of the MVC Framework that convert the code of a view into HTML markup that a browser can understand Are divided in the following two categories: Web Form view engine: Is a legacy view engine for views that use the same syntax as Web Forms. Razor view engine: Is the default view engine starting from MVC 3. This view engine does not introduce a new programming language, but instead introduces new markup syntax to make transitions between HTML markups and programming code simpler 4 Specifying the View for an Action 1/8 While creating an MVC app, you often need to specify a view that should render the output for a specify action When you create a new project in , the project by default contains a View directory In an app, if a controller action returns a view, your app should contain the following: A folder for the controller, with the same name as the controller without the Controller suffix A view file in the Home folder with the same name as the action 5 Specifying the View for an Action 2/8 Following code shows an Index action that returns an ActionResult object through a call to the View() method of the Controller class: In this code, the Index action of the controller named HomeController that returns the result of a call to the View() method. The result of the View() method is an ActionResult object that renders a view 6 public class HomeController : Controller { public ActionResult Index() { return View(); } } Specifying the View for an Action 3/8 VS . | View Nguyen Ha Giang 1 Objectives Define and describe views Explain and describe the razor engine Define and describe the HTML helper methods 2 Working with Views To display HTML content to the user, you can instruct the controller in the app to return a view. A View Provides the UI of the app to the user Is used to display content of an app and also to accept user inputs Uses model data to create this UI Contains both HTML markup and code that runs on the Web server 3 View Engines Are part of the MVC Framework that convert the code of a view into HTML markup that a browser can understand Are divided in the following two categories: Web Form view engine: Is a legacy view engine for views that use the same syntax as Web Forms. Razor view engine: Is the default view engine starting from MVC 3. This view engine does not introduce a new programming language, but instead introduces new markup syntax to make transitions between HTML markups and programming code simpler 4 Specifying

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.