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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:12:04+00:00 2026-06-12T00:12:04+00:00

I am using the custom RequiredIf attribute created by Simon Ince in my MVC

  • 0

I am using the custom RequiredIf attribute created by Simon Ince in my MVC app.

I have a viewmodel which is passed to the view like this:

public class HistoryViewModel
{
    public Contact ContactModel { get; set; }
    public Account AccountModel { get; set; }
    public Person PersonModel { get; set; }
 }

I have a bunch of models with all the props in them (i.e. contact.cs, account.cs, person.cs)

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public bool IsAdult { get; set; }        
    [RequiredIf("IsAdult", "Yes", Errormessage="Please leave a comment")]
    public string Comments { get; set; }
 }

The RequiredIf validation does not seem to be working when passed through the viewmodel. It works fine if I move the properties into the viewmodel directly. All other[Required]` attributes work from the model, through the viewmodel.

So do I need to move all the properties into the viewmodel, that need the RequiredIf on them? Or is there another way around this?

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

    Have you tried MVC FoolProof validation? It has support for RequiredIf (and a fair few others) with Client Side support. It can sometimes be a bit buggy but latest version isn’t to bad.

    Works in same way as the above (which I tried before I switched to FoolProof)

       public bool Married { get; set; }
    
        [RequiredIfTrue("Married")]
        public string MaidenName { get; set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using custom model binder in ASP.NET MVC 2 that looks like this:
I am using ASP.NET MVC 2 Preview 2 and have written a custom HtmlHelper
I have build my own custom validation framework for WPF using attribute based validation.
I have created custom validation attribute [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited =
I have created custom attributes for a category in my module's install script like
i am using custom checkbox buttons in my table view and want to save
I have started using custom intents in my application and I have come across
I am using custom row view in ListView widget. I am having getView method
Using MVC2, I have a simple ViewModel that contains a bool field that is
Using this guide I have created a static library (let's call it AppCore )

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.