MVC Updatemodel's failed to update the XXXXX type model

Source: Internet
Author: User

Questions about MVC Updatemodel's failure to update the XXXXX type model:

Recently do MVC3 project, I believe many people have encountered this problem, in this record, exception: Updatemodel's failed to update the XXXXX type model

The following provides a workaround to resolve this exception by looking at Entityvalidationerrors

The workaround for viewing entityvalidationerrors details is as follows:

In the programming of EF, we sometimes encounter such a mistake:

However, follow his hint "See ' entityvalidationerrors ' property for more details." Go to Exception and see only

It is not possible to see the specifics of why that attribute is not validated, and perhaps many people have encountered this situation.

Here we introduce a exception class, which allows us to easily know which field is out of the question.

That is System.Data.Entity.Validation.DbEntityValidationException, believe that the code knows how to write, the simplest is

try{    //Occurrence Exception code}catch (Dbentityvalidationexception dbex) {}

Inside the Dbex, we can see

This way we can see the details of all the validationerrors in Entityvalidationerrors.

So the problem is solved.

MVC Updatemodel's failed to update the XXXXX type model

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.