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

The goals of this chapter are: Define and describe models, explain how to create a model, describe how to pass model data from controllers to view, explain how to create strongly typed models, explain the role of the model binder, explain how to use scaffolding in Visual . | Models Nguyen Ha Giang 1 Objectives Define and describe models Explain how to create a model Describe how to pass model data from controllers to view Explain how to create strongly typed models Explain the role of the model binder Explain how to use scaffolding in Visual 2 Introducing Models A model is class containing properties that represents data of an app A model represents data associated with the app MVC Framework is based on the MVC pattern The MVC pattern defines the following three types of models, where each model has specific purpose: Data model: represent classes that iteract with a database. Data models are set of classes that can either follow the database-first approach or code-first app Business model: represent classes that implement a functionality that represents business logic of an application View model: Represent classes that provide information passed between controllers and views 3 Creating a Model To create a model in an app, you need to: Create a public class Declare public properties for each information that the model represents 4 Accessing a Model within a Controller In an MVC app when a user request for some information, the request is received by an action method. The action method is used to access the model storing the data. To access the model, you need to create an object of the model class and either retrieve or set the property values of the object 5 Passing model data from C to V 1/6 Once you have accessed the model within a controller, you need to make the model data accessible to a view so that the view can display the data to the user. To do this, you need to pass the model object to the view while invoking the view You can model the object as follow: A single object A collection of model objects 6 Passing model data from C to V 2/6 In an action method, you can create a model object and the pass the object to a view by using the ViewBag object. In this code, an object of the User model .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.