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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:47:50+00:00 2026-05-26T21:47:50+00:00

I am working on an mvc3 application and having some problems with getting validation

  • 0

I am working on an mvc3 application and having some problems with getting validation to work as I want.

The application is using buddy classes for the models. (This is something I haven’t used in the past and I am a little confused why they are used…anyway)

I want to add required fields to ensure data been submitted is correct. I have tried adding the required field to the buddy class.

When I submit the form no client-side validation takes place and the debugger steps into the entity frameworks generated code. Here is complains that the fields that contain null values are causing are invalid. If I step through all of those it finally gets to the controller where my if (ModelState.IsValid) is showing false.

I have client-side validation switched on.

Am I meant to be applying the data validation at the buddy class level or at the view model?

One other question is why use buddy classes? to me they seem to over complicate things.

Updated added an example of the buddy class

[MetadataType(typeof (CustomerMetaData))]
public partial class Customer
{
    public string Priorty
    {
        get
        {
            var desc = (Priority) Priority;
            return desc.ToString().Replace('_', ' ');
        }
    }

internal class CustomerMetaData
{
    [Required]
    [DisplayName("Priorty")]
    public string Priorty { get; set; }
  • 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-26T21:47:51+00:00Added an answer on May 26, 2026 at 9:47 pm

    Buddy classes are metadata classes to put data annotation attributes when you are not in control of the original class i.e. can’t edit it. Typical situation is when the class is generated by an ORM like Entity Framework.

    //Can't edit this class
    public partial class YourClass{
      public string SomeField {get; set;}
    }
    
    //Add a partial class
    [MetadataType(typeof(YourClassMetadata))]
    public partial class YourClass{
    }
    
    //And a metadata class    
    public class YourClassMetadata
    {  
      [Required(ErrorMessage = "Some Field is required")]
      public string SomeField {get; set;}
    }
    

    are you sure that you have [MetadataType(typeof(YourClassMetadata))]?

    More about buddy classes here and here

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

Sidebar

Related Questions

I'm working on an ASP.NET MVC 3 application and having some issues. I've got
I am working on a .Net MVC3 application. I have a couple different models
I'm working on a web application project using ASP.NET MVC3 and database in SQL
I am working on an ASP.Net MVC3 application and I'm having trouble understanding the
I'm working on a MVC3 web application. I want a list of categories shown
I have basic client-side validation working in my MVC3 RC2 application, but I'm now
I'm working on a MVC3 application and I created my POCO classes from my
I'm working on an MVC3 web application using the razor view engine. I'm looking
I am working through a KnockOutJs Sample and am having some posting problems with
I am working on asp.net mvc3 application. In this user can post data, i

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.