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