Use form validation in ASP. (The first thing to understand is that the validation logic should be added to the model, view, and Controller.) Since model is responsible for information access and business logic validation, we add the validation logic to the model. )
The first step: refer to the following namespace
Step Two: Add validation
The third step: Start debugging, the following problems occur:
Workaround:
The hyperlink contains a detailed description of the problem, which means that the Entity Framework helps us to automatically adjust the schema within the database through the Code first database migration.
The simplest way to solve this problem is to cut the entire database down to rebuild ( Note: This setting will cause the data in the database to be lost, so don't start the parameter in the production environment )
First step: Locate the database context class in the Model directory: MvcGuestbookContext.cs (the data context class for my project, find my own counterpart) to copy this code:
System.Data.Entity.Database.SetInitializer (New system.data.entity.dropcreatedatabaseifmodelchanges< Mvcguestbook.models.mvcguestbookcontext> ());
The second step: Open the Global.asax document, and at the top of the Application_Start method, add the code copied in the first step, save, start debugging, the problem has been resolved.
Use forms in ASP. NET MVC to validate that a model with context has changed since the database was created, causing debugging to fail