MIS 324 -- Professor Sandvig MIS 324 Professor Sandvig 10/11/2019 MVC Introduction MIS 324 Professor Sandvig
Recap Photos exercise Controller: Handles http requests Request includes: controller name action method name Example: ~/photos/dahlia Action method name optional Defaults to “index”
Recap Controller Parameters ViewBag Give each object a name Example: photos/photoView?id=dahlia Photos/photoView/dahlia ViewBag Passes values from controller to view Give each object a name Eg: ViewBag.photo = “dahlia”;
Today Review photos exercise Models How to define model Benefits How to define model Accessing from controller Passing to view
What is Model Model describes data Typically a real-world entity Customer Product Order Transaction Etc.
Benefits of Models Model defines data Pass all fields as object Datatypes Pass all fields as object Visual Studio Examines model: Create forms Validation
Benefits of Models Visual Studio wizards Uses model to create forms Includes Validation
How to Define Model Add new class to model folder Syntax:
Accessing Model from Controller Need to add using statement Points to “Models” namespace
Passing Model to from Controller
MIS 324 -- Professor Sandvig 10/11/2019 Summary MVC Models Define business entities Employees Customers Products All properties in single object Pass as single object Validation in definition Visual Studio wizards