Using AJAX object with ASP.NET WEB API

2

Index

Stats

12,497 visits, 29,589 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 8 Dec, 2014. Last updated 12 Oct, 2020

About MVC

ASP.NET is based on the MVC: Model - View - Controller software design pattern. It is a god practice for code organizing and maintantence. Other platforms, like iOS are based on the MVC pattern too.

First pass: Creating our first Model

Now we will crete our first Model. A Model is simply a class (an object-oriented programing concept). To create a Model class, you will:

1. Right click the Models folder, and choose Add > Class...

2. Give a name to it. Let's call it PlayerData and click Add

Adding properties to our PlayerData class

Inside the PlayerData class we can add the PlayerData's atributes, so lets add 3 properties: Id, Name and HiScore. Futurely it will be stored in the database automatically for us ;)

The complete PlayerData class will be:

    public class PlayerData
    {
        public int Id { get; set; } // The player ID in the database
        public string PlayerName { get; set; } // The player nick name
        public int HiScore { get; set; } // The hight score in the game
    }

Click Save in the toolbar or press Ctrl + Shift + S to save all.

Before continue...

Now, try to build the project by clicking BUID > Build Solution. If it fails, go back and revise your code.

Automatic database generation by Entity Framework

Entity Framework is an ORM: Object-Relational Mapping that is capable to generate databases automaticaly for us, we don't need to do nothing, once the project is started for the first time a database will be automatically generated based in our Model classes, it is called Code Fist. Tip: To open a database file, double click on it inside the App_Data folder of your project.

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!