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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:07:16+00:00 2026-05-26T22:07:16+00:00

My task is to perform validation on form which fields are constructed dynamically(upon database

  • 0

My task is to perform validation on form which fields are constructed dynamically(upon database query). I would like to use data annotations. While model is dynamic I can’t decorate properties with annotations, but I can use custom metadata provider for example inheriting from DataAnnotationsModelMetadataProvider.

Simply in global.asax at Application_start I supplied my own MetaDataProvider:

ModelMetadataProviders.Current = new MetadataProvider.CustomModelMetadataProvider();

I made a little hack, cause ModelMetadataProviders.Current is per application, my problem needed serving different metadata in each request, but it was not so hard.

This work fine for emulating IsRequired attribute, because metadata provider uses System.Web.Mvc.ModelMetadata and there is IsRequired property , but there is no property such as RegularExpression or anything similar.

So I run debugger and looked at ModelMetadata returned by original DataAnnotationsModelMetadataProvider for property with RegularExpression attribute, and I hadn’t found regular expression there anyway.

I would love to get some hints on that.

  • 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-26T22:07:17+00:00Added an answer on May 26, 2026 at 10:07 pm

    I figured answer (by inspecting MVC 3 source code) which is as follows:

    1. create custom ModelValidatorProvider for example inheriting from DataAnnotationsModelValidatorProvider
    2. override GetValidators method
    3. add yout custom provider to ModelValidatorProviders.Providers collection

    GetValidators method returns IEnumerable<ModelValidator> so its enough to return RegularExpressionAttributeAdapter which inhertis from ModelValidator.

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

Sidebar

Related Questions

I have a task to perform an HttpWebRequest using Task<WebResponse>.Factory.FromAsync(req.BeginGetRespone, req.EndGetResponse) which can obviously
I have an oddly difficult task to perform. I thought it would be easy,
I want perform a easy task in android, which when receiving a call the
Is it even possible to perform address (physical, not e-mail) validation? It seems like
I've got a fairly extensive data entry task to perform in a PHP application.
I am using Ant's <parallel> task to perform multiple simultaneous targets that use <exec>
I have a jQuery function already to perform the task I need but is
I was wondering whether anyone knows of any tools available that perform the task
I have a task I need to perform, do_stuff(opts) , that will take ~1s
I was asked to perform(first time) a task in PHP with PostgreSQL for the

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.