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

The Archive Base Latest Questions

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

I have a simple form which is using ASP.NET MVC 3 unobtrusive client side

  • 0

I have a simple form which is using ASP.NET MVC 3 unobtrusive client side validation.

The model looks a bit like this (names changed for privacy):

public class MyInputModel
{
    public MyInputModel()
    {
    }

    public MyInputModel(MyViewData viewData)
    {
        ViewData = viewData;
        MaxValueForSize = viewData.MaxSize;
    }

    public int MaxValueForSize { get; set; }


    [RegularExpression("[1-9][0-9]*",ErrorMessage = "The value must be a whole number.")]
    public int Size { get; set; }

    [StringLength(255)]
    [Required]
    public string Description{ get; set; }
}

In my view I put a hidden field in for MaxValueForSize and I want to compare the entered value for Size to less than or equal to the MaxValueForSize property.

I know I can do this server side by overriding validation attribute like so:

internal class SizeValidAttribute : ValidationAttribute
{
    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        if(value != null)
        {
            var model = (MyInputModel) validationContext.ObjectInstance;


            if ((int)value > model.MaxValueForSize)
                return new ValidationResult(ErrorMessage);

        }
        return base.IsValid(value, validationContext);
    }
}

However I would like to (need to) have client side validation on this property. Similar to how the Compare annotation works.

Does anyone know of a way to do this? Do I need to extend the client side validation somehow?

Thanks for your help.

  • 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-20T22:12:08+00:00Added an answer on May 20, 2026 at 10:12 pm

    Have a look at this article. It explains how to extend the ASP.NET MVC model validation to support cross-field validation:

    Extending ASP.NET MVC’s Validation
    http://blogs.msdn.com/b/mikeormond/archive/2010/10/05/extending-asp-net-mvc-s-validation.aspx

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

Sidebar

Related Questions

I have various simple ASP.NET MVC views for CRUD operations which work fine on
I am writing a SharePoint web part which will have a simple ASP.NET form.
I have a simple ASP.Net MVC View which contains an FCKeditor text box (created
I have developed a web app in ASP.NET MVC which we are using internally.
I am using Simple Modal with asp.net MVC. I have set it up using
I have a simple MVC form with the following elements: <%= Html.TextBox(FechaInicio) %> Which
I have a ASP.NET MVC 3 view with esentially two forms, but which reside
I have an ASP.NET MVC (using the release candidate) application that works with a
In my asp.net webform page I have a simple form with a single inputfield
I'm writing a contact form in ASP.NET MVC. The user will have the ability

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.