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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:08:28+00:00 2026-06-09T17:08:28+00:00

Really struggling with the in-built unobtrusive jquery validation set up by MVC3. My object

  • 0

Really struggling with the in-built unobtrusive jquery validation set up by MVC3.

My object has a property like:

    [DisplayName("GP")]
    [DataType(DataType.Currency)]
    [DisplayFormat(NullDisplayText = "$0", DataFormatString = "{0:C0}", ApplyFormatInEditMode = true)]
    [Column("gross_profit")]
    public decimal? GrossProfit { get; set; }

The EditorFor makes a text box, which is fine, however validation fails because I want users to be able to enter currency prefixes… e.g. $48,000.. client side validation fails, saying the property is not a number.

I don’t have a problem writing my own data annotations, and custom model binding for this, but I can’t figure out how to stop MVC from automatically putting in that “data-val-number” into the text input just because it’s of type decimal.

I believe that “data-val-number” is stopping jquery unobtrusive validation from passing because the input field contains a dollar sign, and maybe a comma.

So i’m not looking for any globalisation tips, rather a way to allow user to enter text like “$48,000” and have this pass validation…

I would want to follow the same approach for percentage values also… e.g. “25%”

  • 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-09T17:08:29+00:00Added an answer on June 9, 2026 at 5:08 pm

    You don’t want to use non-numeric values inside a decimal? property for display. There are a few ways to handle this but the default model binder in MVC will always try to explicitly map a ######.## to a decimal field. If you have auxiliary input such as $##,###.## it’ll blow up because that cannot be directly cast to a decimal value.

    You have 2 solutions, the first is to use input masking like:

    http://www.xaprb.com/html-input-mask/html-form-input-mask.html

    or

    http://digitalbush.com/projects/masked-input-plugin/

    Which tweaks only the UI display of the input.

    Or you can use the same logic you have in the model with a string data type.

    [DisplayName("GP")]
    [DataType(DataType.Currency)]
    [DisplayFormat(NullDisplayText = "$0", DataFormatString = "{0:C0}", ApplyFormatInEditMode = true)]
    [Column("gross_profit")]
    public string CurrencyDisplay { get; set; }
    
    public decimal? CurrencyInput 
    {
        get
        {
            //parse out non-int fields to return from value in CurrencyDisplay
        }
    
        set
        {
            //format string and seed into CurrencyDisplay
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really struggling with require.js and jquery mobile. I have a loosely based file
I'm really struggling trying to use the jQuery UI autocomplete plugin. I've had a
I'm really struggling with this. I have a flash demo built in AS2 (not
I'm really struggling with a jQuery animation. Please see jsfiddle where I have posted
Really struggling to figure this out. Just trying to take in data from php
Im really struggling to get my head round this. Im using c#. I want
I'm really struggling to get my head around Drupal Form API...actually Drupal as a
I'm really struggling with the Javascript version of Regular Expression matching, despite knowing how
I'm really struggling with this. I have a viewdetails.php page, addnew.php page and a
I'm really struggling to understand cocos2d 2.0 and how its layers and coordinates work.

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.