1 / 13

Jon Galloway | Development Platform Evangelist Christopher Harrison | Microsoft Certified Trainer

02 | Developing ASP.NET MVC 4 Models. Jon Galloway | Development Platform Evangelist Christopher Harrison | Microsoft Certified Trainer. Module Overview. Working with MVC Models Working with Data. Lesson 1: Creating MVC Models.

cole-rose
Télécharger la présentation

Jon Galloway | Development Platform Evangelist Christopher Harrison | Microsoft Certified Trainer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 02 | Developing ASP.NET MVC 4 Models Jon Galloway | Development Platform Evangelist Christopher Harrison | Microsoft Certified Trainer

  2. Module Overview • Working with MVC Models • Working with Data

  3. Lesson 1: Creating MVC Models • Developing Models Using Display and Edit Data Annotations on Properties Validating User Input with Data Annotations What Are Model Binders? Model Extensibility Demonstration: How to Add a Model

  4. Developing Models public class Photo { publicintPhotoID { get; set; } publicstring Title { get; set; } publicbyte[] PhotoFile { get; set; } publicstring Description { get; set; } publicDateTimeCreatedDate { get; set; } publicstring Owner { get; set; } publicvirtualList<Comment> Comments { get; set; } }

  5. Display and Edit Data Annotations public class Photo { // other properties excluded [DisplayName("Picture")] publicbyte[] PhotoFile { get; set; } [DataType(DataType.MultilineText)] publicstring Description { get; set; } [DataType(DataType.DateTime)] [DisplayName("Created Date")] [DisplayFormat(DataFormatString = "{0:dd/MM/yy}"] publicDateTimeCreatedDate { get; set; } }

  6. Validating User Input with Data Annotations public class Person { public intPersonID { get; set; } [Required(ErrorMessage="Please enter a name.")] public string Name { get; set; } [Range(0, 400)] public intHeight { get; set; } [Required] [DataType(DataType.EmailAddress)] public string EmailAddress { get; set; } }

  7. What Are Model Binders? • The Default Controller Action Invoker uses model binders to determine how parameters are passed to actions • The Default Model Binder passes parameters by using the following logic: • The binder examines the definition of the action that it must pass parameters to • The binder searches for values in the request that can be passed as parameters

  8. How to Add a Model

  9. Lesson 2: Working with Data • The Entity Framework Using an Entity Framework Context Data Access in Models and Repositories

  10. The Entity Framework Types of Entity Framework Workflows • Database First • Model First • Code First

  11. How to Use Entity Framework Code

  12. Data Access in Models and Repositories Model Model Repository Database Database

More Related