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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:16:09+00:00 2026-05-22T16:16:09+00:00

I have an MVC application which I have added custom cross-field validation. The cross-field

  • 0

I have an MVC application which I have added custom cross-field validation. The cross-field validation isn’t configured to be client-side however when I tab through my fields IE is throwing the following error “$.validator.method[…] is null or not an object” from within jquery.validate.js. I have attached the full version so I can debug what’s going on and it seems to be trying to fire my “mandatoryif” custom validation below on the client-side and then throwing the error at the following line:

var result = $.validator.methods[method].call( this, element.value.replace(/\r/g, ""), element, rule.parameters );  

Any ideas why it is trying to do this when the “mandatoryif” validation hasn’t been added client-side?

I have also updated to the latest version as I read it could be the version of jQuery.validate but this didn’t fix the issue either.

Here is my custom validation:
Attribute

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class MandatoryIfAttribute : ValidationAttribute, ICrossFieldValidationAttribute
{       
    public string OtherProperty { get; set; }

    public bool IsValid(ControllerContext controllerContext, object model, ModelMetadata modelMetadata)
    {
        if (model == null)
        {
            throw new ArgumentNullException("model");
        }

        // Find the value of the other property.
        var propertyInfo = model.GetType().GetProperty(OtherProperty);
        if (propertyInfo == null)
        {
            throw new InvalidOperationException(string.Format("Couldn't find {0} property on {1}.",
                                                              OtherProperty, model));
        }

        var otherValue = propertyInfo.GetGetMethod().Invoke(model, null);

        if (modelMetadata.Model == null)
        {
            modelMetadata.Model = string.Empty;
        }

        if (otherValue == null)
        {
            otherValue = string.Empty;
        }

        return (String.IsNullOrEmpty(modelMetadata.Model.ToString()) && (String.IsNullOrEmpty(otherValue.ToString()) || otherValue.ToString() == "0")) || (!String.IsNullOrEmpty(modelMetadata.Model.ToString()) && String.IsNullOrEmpty(otherValue.ToString())) || (!String.IsNullOrEmpty(modelMetadata.Model.ToString()) && !String.IsNullOrEmpty(otherValue.ToString()));
    }

    public override bool IsValid(object value)
    {
        // Work done in other IsValid
        return true;
    }

Validator

public class MandatoryIfValidator : CrossFieldValidator<MandatoryIfAttribute>
{       
    public MandatoryIfValidator(ModelMetadata metadata, ControllerContext controllerContext,
                                    MandatoryIfAttribute attribute) :
        base(metadata, controllerContext, attribute)
    {
    }

    public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
    {
        var rule = new ModelClientValidationRule
        {
            ValidationType = "mandatoryif",
            ErrorMessage = Attribute.FormatErrorMessage(Metadata.PropertyName),
        };

        rule.ValidationParameters.Add("otherProperty", Attribute.OtherProperty);

        return new[] { rule };
    }

Appreciate any help on 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-05-22T16:16:09+00:00Added an answer on May 22, 2026 at 4:16 pm

    I have managed to find the answer to my query. Because some of my custom validation was doing lookups to the db I didn’t want the overhead of this being done client-side so there was no client-side code. However, I didn’t realise that by adding

    DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(MandatoryIfAttribute),
    typeof(MandatoryIfValidator));

    in Global.asax that it was in affect adding this client-side. Of course because there was no code to process client-side it was throwing the validaiton error.

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

Sidebar

Related Questions

I have MVC webApi application which works with Unity . I have to resolve
I have an MVC application which is my marketing website, and two other regular
I have an MVC application which has a set of fields for contact details
I have a Spring MVC application which uses FreeMarker as View technology (But maybe
I have a C# MVC application which I need to output the following data
I have a ASP.NET MVC application which is build up as an assembly that
I have an ASP.NET MVC 3 application which has a post action called Create
I have an .NET 4.0 ASP.NET MVC application, which also hosts a Workflow Foundation
I have a Clustered Windows Hosting site which currently hosts an MVC Web Application
In the asp.net mvc 3 application I have two views which have the same

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.