What is the role of the PageModel class in Razor Pages?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "To handle HTTP requests and provide data to the Razor Page." PageModel là lớp code-behind của một Razor Page: nó chứa các handler OnGet, OnPost, OnGetAsync... để xử lý request theo phương thức HTTP, chứa các thuộc tính được model binding gán dữ liệu từ request, và cung cấp dữ liệu cho phần giao diện .cshtml truy cập qua @Model. Nói cách khác nó gộp vai trò của controller và view model trong MVC. Định nghĩa lược đồ cơ sở dữ liệu ("To define database schemas.") là việc của entity và DbContext; quản lý phiên ("To manage user sessions.") là của Session; bố cục giao diện ("To define user interface layouts.") do _Layout.cshtml đảm nhiệm.