Use forms in ASP. NET MVC to validate that a model with context has changed since the database was created, causing debugging to fail

Source: Internet
Author: User

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

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.