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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:12:00+00:00 2026-05-23T16:12:00+00:00

I have a property on my view model that is a custom class with

  • 0

I have a property on my view model that is a custom class with a value property.

e.g.

class mycustomobj
{ 
     public int? Value {get; set; } 
}

public class myviewmodel
{
    [DefaultablePercentRange]
    public property mycustomobj { get; set; }
}

I have a custom range attribute DefaultablePercentRange that I decorate this property with so that I can check apprpiate inputs. Associated with this is the relevant javascript validator for clientside.

The javascript is:

Sys.Mvc.ValidatorRegistry.validators["defaultablePercentRange"] = function (rule) {

var _minimum = rule.ValidationParameters["minimum"];
var _maximum = rule.ValidationParameters["maximum"];

return function (value, context) {

    if (!value || !value.length) {
        return true; // return true as null values allowed
    }

    var n = Number.parseLocale(value);
    return (!isNaN(n) && _minimum <= n && n <= _maximum);
};

}

I am also using Html.EditorFor on my view with templates so that I can output the property as mycustomobj.Value rather than just mycustomobj . So the view property in html ends up being rendered something like:

<input class="defaultable tiny" default="0" defaultwhen="0" id="mycustomobj_Value" name="mycustomobj.Value" type="text" value="" placeholder="0" style="">

Now my problem is the javascript validation is passing null into my clientside validators function. After a fair amount of investigation I have identified this being because the JSON created for my custom DataAnnotationsModelValidator is not using the full id of the property. For example the JSON created is:

{"FieldName":"mycustomobj","ReplaceValidationMessageContents":true,"ValidationMessageId":"mycustomobj_validationMessage","ValidationRules":[{"ErrorMessage":"This value must be in the range 0 - 100","ValidationParameters":{"minimum":0,"maximum":100},"ValidationType":"defaultablePercentRange"},{"ErrorMessage":"This value must be in the range 0 - 100","ValidationParameters":{"minimum":0,"maximum":100},"ValidationType":"defaultablePercentRange"}]}

Where I need:
{“FieldName”:”mycustomobj.value”,”ReplaceValidationMessageContents”:true,”ValidationMessageId”:”mycustomobj_value_validationMessage”,”ValidationRules”:[{“ErrorMessage”:”This value must be in the range 0 – 100″,”ValidationParameters”:{“minimum”:0,”maximum”:100},”ValidationType”:”defaultablePercentRange”},{“ErrorMessage”:”This value must be in the range 0 – 100″,”ValidationParameters”:{“minimum”:0,”maximum”:100},”ValidationType”:”defaultablePercentRange”}]}

My question is. How can I get the right property name serialized out for the clientside validation so that my clientside validation will work. My serverside works just fine.

Please let me know if anyone needs more info.

  • 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-23T16:12:00+00:00Added an answer on May 23, 2026 at 4:12 pm

    I ended up getting around this by using a combination of factors.

    • Created a model binder specifically for mycustomobj that knows how to set the value on mycustomobj
    • changed template so that .Value was output but the control name was still just property name

    This meant that when binding back to the viewmodel on post I can ensure the correct property on mycustomobj was set. And in the javascript the javascript client validation code was being called appropiately as the correct input id was being set.

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

Sidebar

Related Questions

If I have a property: public list<String> names { get; set; } How can
Imagine I have a property defined in global.asax. public List<string> Roles { get {
C#, MVC 2 RC 2... I have the following property on my model class:
I have a problem with a bound property of a custom view. The property
I have a ViewModel that looks like this: public class CreateReviewViewModel { public string
In my ViewModel, I have a class A with a child property B that
I have a model which has a boolean property and some other properties that
I have a property called IsSecureConnection that is part of my object's interface. This
I have a property on a domain object that is declared in a many-to-one
If I have a property that I want to let inheritors write to, but

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.