Model Code:
public partial class Content
{
public int ID { get; set; }
[Required(ErrorMessage = "Required.")]
public string ContentText1 { get; set; }
}
The view doesn't contain any Field related to Content.
Server side code on save (Controller Code):
Content c = new Model.Content();
db.Contents.Add(c);
db.Entry(pc).State = System.Data.Entity.EntityState.Added;
db.SaveChanges();
This results in an error:
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
Is it possible to prevent this error without changing the model?
Contentobject andContentText1is required then it must be validated. It's a more common scenario to want to skip validation on some properties when updating. - Gert Arnold