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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:45:00+00:00 2026-06-07T00:45:00+00:00

i have a problem with my mvc3 application, i need to create some Validation

  • 0

i have a problem with my mvc3 application, i need to create some Validation stuff. but i dont have a normal model class because i have used EF with the database first approach.

i can not just open the class and write something like:

[Required]
[StringLength(10)]

how to solve this problem?

  • 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-06-07T00:45:03+00:00Added an answer on June 7, 2026 at 12:45 am

    You could use the MetadataType attribute. So let’s suppose that EF spit at your face the following class which you cannot modify:

    public partial class Foo
    {
        public string Bar { get; set; }
    }
    

    Now you could extend it since it is a partial class:

    [MetadataType(typeof(FooMetadata))]
    public partial class Foo
    {
    }
    

    and then define the metadata:

    public class FooMetadata
    {
        [Required]
        [StringLength(10)]
        public string Foo { get; set; }
    }
    

    Or, simply throw data annotations away and use a real validation framework such as FluentValidation.NET (which I use and strongly recommend) allowing you to express complex validation rules on your models in a fluent manner, has an excellent integration with ASP.NET MVC and also allows you to elegantly unit test your vaildation logic in isolation.

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

Sidebar

Related Questions

I have a problem with a model in a asp.net mvc3 application. First of
I have problem with create ulr routing for asp.net mvc3 application. My project has
i have a problem with the asp.net MVC3. when i create a new project
My Problem: I have an MVC3 application where all views use a common master
I'm learning ASP.NET MVC3 and doing an application with CMS capabilities - but have
I'm about to create an ASP.net MVC3 application where I need to make a
I have mvc3 application here my problem is on same page i.e on Index.cshtml
Using MVC3 with NHibernate, I am having a problem with dropdowns. I have a
I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have problem with show or hide form in Window Form Application. I start

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.