In ASP. net mvc, the context model is changed after the database is created using Form Verification, causing debugging failure. asp. netmvc
Use Form Verification in ASP. net mvc. (First of all, you need to understand which verification logic should be added to Model, View, and Controller? Because the Model is responsible for information access and business logic verification, we add the verification logic to the Model .)
Step 1: reference the following namespace
Step 2: Add Verification
Step 3: start debugging and the following problems occur:
Solution:
The Hyperlink contains a detailed introduction to solve this problem, that is, the Entity Framework helps us automatically adjust the architecture in the database by migrating the Code First database.
The simplest way to solve this problem is to cut and recreate the entire database.(Note: This setting will cause all data in the database to be lost. Do not start the parameter in the production environment)
Step 1: Find the database context class in the Model Directory: MvcGuestbookContext. cs (my project's data context class, find your own) and copy this Code:
System. Data. Entity. Database. SetInitializer (new System. Data. Entity. DropCreateDatabaseIfModelChanges <MvcGuestbook. Models. MvcGuestbookContext> ());
Step 2: Open the Global. asax document, add the code copied in step 1 at the top of the Application_Start method, save it, and start debugging. The problem has been solved.