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

  • Home
  • SEARCH
  • 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 4056516
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:50:14+00:00 2026-05-20T14:50:14+00:00

I have the following class public partial class Contact { public Contact() { }

  • 0

I have the following class

public partial class Contact
{
    public Contact()
    {
    }

    #region Primitive Properties

    public virtual int Id { get; set; }

    [Display(ResourceType = typeof(Common), Name = "Person_Name")]
    [Required(ErrorMessageResourceName = "Validation_Required", ErrorMessageResourceType = typeof(Common))]
    [StringLength(100, ErrorMessageResourceName = "Incorrect_Field_Length",
        ErrorMessageResourceType = typeof(Common))]
    public virtual string Name { get; set; }

    [Display(ResourceType = typeof(Common), Name = "Telephone_Number")]
    [DataType(DataType.PhoneNumber)]
    [StringLength(100, ErrorMessageResourceName = "Incorrect_Field_Length",
        ErrorMessageResourceType = typeof(Common))]
    [Required(ErrorMessageResourceName = "Validation_Required", ErrorMessageResourceType = typeof(Common))]
    public virtual string Telephone { get; set; }

    [Display(ResourceType = typeof(Common), Name = "EmailAddress")]
    [DataType(DataType.EmailAddress)]
    [StringLength(255, ErrorMessageResourceName = "Incorrect_Field_Length",
        ErrorMessageResourceType = typeof(Common))]
    [Required(ErrorMessageResourceName = "Validation_Required", ErrorMessageResourceType = typeof(Common))]
    public virtual string Email { get; set; }

    [Display(ResourceType = typeof(Common), Name = "ContactType")]
    public virtual ContactType ContactType { get; set; }

    public virtual Company Company { get; set; }

    #endregion
}

The ContactType looks like this

public partial class ContactType
{
    #region Primitive Properties

    public virtual int Id { get; set; }

    [Display(ResourceType = typeof(Common), Name = "ContactType_Name")]
    [StringLength(50, ErrorMessageResourceName = "Incorrect_Field_Length",
        ErrorMessageResourceType = typeof(Common))]
    [Required(ErrorMessageResourceName = "Validation_Required", ErrorMessageResourceType = typeof(Common))]
    public virtual string Name { get; set; }

    #endregion
}

The problem I have is that when I edit the Contact object, ModelState.IsValid is always false. This is due to the Name within the ContactType being Null, it has the correct id. This is because the ContactType is selected by a dropdown selection. I don’t want to remove the validation from ContactType as it is needed when adding new ContactType objects. Any idea how I can get around this issue?

Please shout if I need to provide more information.

Cheers

  • 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-20T14:50:14+00:00Added an answer on May 20, 2026 at 2:50 pm

    When you validate Contact, you shouldn’t validate the ContactType property as that property will never be properly send by the user. Validating a ContactTypeId of int type property should solve this issue and leave you ContactType validation intact.

    I’m not sure what data access framework you are using (looks like EF Code First) but in EF Model First you can activate the generation of foreign-key properties on top of the usual navigation properties which makes add/edit scenarios much easier (specially in the web where you only pass values and not full objects).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class public class Car { public Name {get; set;} }
I have the following class objects: public class VacancyCategory { public int ID {
I have the following situation: class A { public: A(int whichFoo); int foo1(); int
Say I have the following class MyComponent : IMyComponent { public MyComponent(int start_at) {...}
I have the following class declared: public partial class MainWindow : Window And I
I have the following class... public class MyCustomLogger { public static int DEFAULT_INFO =
I have the following object: public partial class Game { public bool Finished {
I have following class as the main window: public partial class Window1 : Window
I have the following that I'm using in every page: public partial class Pages_MyPage
I have the following class: public abstract class AbstractParent { static String method() {

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.