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 6978555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:46:20+00:00 2026-05-27T17:46:20+00:00

I am having an issue with validation in EF models, that I cannot quite

  • 0

I am having an issue with validation in EF models, that I cannot quite seem to figure out. The unobtrusive Javascript validation part works as expected.

Consider the following models (the RequiredIf attribute is from this library):

public class Conversation
{
    public int Id { get; set; }
    public User User { get; set; }
    public String Handler { get; set; }
}

[ComplexType]
public class User
{
    public bool Anonymous { get; set; }
    [RequiredIf("Anonymous", false)]
    [Display(Name = "Full name")]
    public String Name { get; set; }
}

My editor view only shows fields for User, and this is my controller.

    [HttpPost()]
    public ActionResult Create(Conversation conversation)
    {
        if (ModelState.IsValid)
        {
            _db.Conversations.Add(conversation);
            _db.SaveChanges(); // fails on this line
        }
        return RedirectToAction("Index");
    }

This results in the following error:

DbUnexpectedValidationException: An unexpected exception was thrown during validation of 'Full name' when invoking Mvc.ValidationToolkit.RequiredIfAttribute.IsValid. See the inner exception for details.

And the inner exception:

Member 'Conversation.Anonymous' not found.

Why is the validation suddenly looking for Conversation.Anonymous, and not Conversations.Client.Anonymous?

  • 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-05-27T17:46:20+00:00Added an answer on May 27, 2026 at 5:46 pm

    You shouldn’t be using your entities directly in your view. Create a View Model that is specific to your views and then use something like AutoMapper to map the domain objects to your view models. Put all the required, length, etc. validations on your view model.

    var model = Mapper.Map<Conversation, ConversationViewModel>(conversation);
    
    return View(model);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a strange validation issue that I can't seem to figure out. Why
I'm having a validation issue that I can't figure out. I know I have
I'm having an issue using Stripes validation method. It works but rather than returning
Having an issue here that I have tried everything I can think of but
I'm having an issue with a query that currently uses LEFT JOIN weblog_data AS
I am having an issue where Tomcat is treating extra path information as part
I'm having an issue with a standard ASP.NET page that has a TextBox and
I am having an issue with the JQuery Validation Plugin . I'm using it
I am having an issue with ASP.NET MVC3 client side validation. My view is
It appears someone else is having this issue: Validation.HasError does not trigger again if

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.