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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:08:26+00:00 2026-05-25T18:08:26+00:00

I consume an API that has a full object set. I don’t want to

  • 0

I consume an API that has a full object set. I don’t want to have to re-create an object model in the mvc3 code just to use the DataAnnotations.

Is there a way to use this feature with out a wrapper class? The objects have their own validation rules that I can reuse, but want to use the built in mvc framework to display the messages back.

  • 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-25T18:08:27+00:00Added an answer on May 25, 2026 at 6:08 pm

    You can create a class which inherits from DataAnnotationsModelMetadataProvider, where you can consume your object set, and write out the items as DataAnnotations. A brief example:

    public class MyModelMetadataProvider : DataAnnotationsModelMetadataProvider
    {
        private MyEntities _db = new MyEntities();
    
        protected override ModelMetadata CreateMetadata(
            IEnumerable<Attribute> attributes, 
            Type containerType, 
            Func<object> modelAccessor, 
            Type modelType, 
            string propertyName)
        {
            var modelMetadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
    
            // load object
            var objectSet = _db.ObjectSets.FirstOrDefault(x => x.PropertyName == propertyName);
    
            // check attributes
            if (objectSet.IsRequired)
                modelMetadata.IsRequired = true;
    
            return modelMetadata;
        }
    }
    

    Then, register your provider in Global.asax.cs in the Application_Start method, as follows:

            ModelMetadataProviders.Current = new MyModelMetadataProvider();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that has paperclip attachments. The model might be used in
Facebook has a new Batch request Graph API that I'm trying to consume. The
I'm writing a C# application that has to consume a C++ api provided by
Our app consumes an API, and its data model has a set of entities
I want to consume wordpress XMLRPC API for my latest experiment. Do you know
I am interacting with an API that just has static functions, and cannot be
I have been working on an iPhone app that has a feature of uploading
Given: A C# calculation engine that loads an object model, crunches huge amounts of
We are about to create an API so that our customers can connect to
I am currently trying to consume an API that is working fine in my

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.