MVC-08 model

SECTION 7: Adding data model.

MVC model

MVC model contains all the application logic (business logic, validation logic, data access logic), in addition to the pure view and controller logic.

By MVC, the model can be saved and operation of the application data.

Models folder

Models folder contains the class represents the application model.

Visual Web Developer automatically creates a AccountModels.cs file that contains the model for application security.

AccountModels contains LogOnModel, ChangePasswordModel and RegisterModel.

Adding database model

Creating steps:

In Solution Explorer , right-click the Models folder, select Add: class.

Class MovieDB.cs named, and then click Add .

Edit this category:

 

the System the using; 
the using the System.Collections.Generic; 
the using the System.Linq; 
the using the System.Web; 
the using to System.Data.Entity; 

namespace MvcDemo.Models 
{ 
public class MovieDB 
{ 
public int ID {GET; SET;} 
public String {GET the Title ; SET;} 
public String Director {GET; SET;} 
public the DateTime a Date {GET; SET;} 

} 
public class MovieDBContext: the DbContext 
{ 
public DbSet <MovieDB> Movies {GET; SET;} 
} 
} 
Note: we have this table named "MovieDBs" (ending s). In the previous chapter, we saw the name "MovieDB" for database tables
(Ending s) for the data model. This naming convention is to ensure that the controller and database tables linked. 
Adding controller database
creation steps:
1. Rebuild your project: Select the test, then select Build MvcDemo from the menu.
2. In Solution Explorer, right-click the Controllers folder and select Add, Controller.
3. The controller name is set to: the MoviesController
4. Select the template: with the Controller Read / Write Action and views, the using the Entity Framework
5. The model selection class: MovieDB (MvcDemo.Models)
6. The selected data context categories: MovieDBContext (MvcDemo. Models)
7. select view Razor (CSHTML)
8. click Add
Visual Web Developer creates the following files:
the Controllers folder MoviesController.cs file
Movies views file folder in the folder
to add a database view
the following files are automatically in the Movies create a folder:
1.Create
2.Delete
3.Details
4.Edit
5.Index





Guess you like

Origin www.cnblogs.com/ximi07/p/11027567.html