In ASP. net mvc, the context model is changed after the database is created using Form Verification, causing debugging failure. asp. netmvc

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.