Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:27:56+00:00 2026-06-15T22:27:56+00:00

I have recently created a new application that is using MVC4 and EF5. The

  • 0

I have recently created a new application that is using MVC4 and EF5. The tables already existed, so we are using Database first. This is all new to me, it is my first time in MVC or EF.

I have some models in my EMDX file, and in one of them I inherited IValidatableObject and put some code in the Validate function. This was working fine, then I changed my view to use a ViewModel, now I get an error from validate, and I am stumped. It is still calling my validate function, but no longer posting it back to the screen, i just get a yellow screen.

Error:

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

Model:

public partial class Names : IValidatableObject {
  public int Id { get; set; }
  public string Name { get; set; }
  public bool Active { get; set; }

  public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
    // some logic, this works
  }
}

ViewModel:

public class NamesVM {
  public Names Name { get; set; }
  // some other stuff in this model, but not part of this problem
}

Controller: Edit Function:

[HttpPost]
public ActionResult Edit(NamesVM nvm) {

  if (ModelState.IsValid) {
    dbCommon.Entry(nvm.Name).State = EntityState.Modified;
    dbCommon.SaveChanges();
    return RedirectToAction("Index");
  }

  return View(nvm);
}

View:

@model NamesVM
<div class="editor-label">
  @Html.LabelFor(model => model.Name.Id)
</div>
<div class="editor-field">
  @Html.EditorFor(model => model.Name.Id)
  @Html.ValidationMessageFor(model => model.Name.Id)
</div>

<div class="editor-label">
  @Html.LabelFor(model => model.Name.Name)
</div>
<div class="editor-field">
  @Html.EditorFor(model => model.Name.Name)
  @Html.ValidationMessageFor(model => model.Name.Name)
</div>

<div class="editor-label">
  @Html.LabelFor(model => model.Name.Active)
</div>
<div class="editor-field">
  @Html.EditorFor(model => model.Name.Active)
  @Html.ValidationMessageFor(model => model.Name.Active)
</div>
<input type="submit" value="Save" />

The codes works fine if everything is correct on the screen, but when validation fails, i don’t get a nice error, I get a yellow screen. I am sure I am missing something, I just don’t know what.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:27:57+00:00Added an answer on June 15, 2026 at 10:27 pm

    finally solved it. The IValidatableObject needs to be moved to the ViewModel, as well as the logic for it.

    Model

    public partial class Names { //: IValidatableObject { //Remove the IValidateableObject from here
        public int Id { get; set; }
        public string Name { get; set; }
        public bool Active { get; set; }
    
        // this whole method can be commented out
        //public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
            // some logic, this works
        //}
    }
    

    View Model

    public class NamesVM : IValidatableObject { // add the IValidatableObject to your view model
        public Names Name { get; set; }
            // some other stuff in this model, but not part of this problem
    
        // and move your validation logic to here
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
            // some logic, this works
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently created a new rails 3 application, using the code that I
I have recently just created Java project using Eclipse that requires 2 JAR files
Recently I have been working on upgrading a big web application that was using
I have recently created a HTML5 canvas animation (also using Processing.js). The problem is
I have recently created an application for wp7. Now i am ready submit an
I have recently created a web project in Java using eclipse. I have a
I have the need to expand an asp.net 2.0 web application that I recently
I have recently created a Rails application to handle parent comments for a company
Recently I got a client that wanted to have new features and a different
I've recently started using MEF in my application, and have had no issues using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.