Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 3 decimal server-side validation problem

I´m using JQuery Unobtrusive validation... I´m configured with Globalize to accept numbers like that : 1.500,50 (Masked by JQuery)

My code so far

1- ) Configured Globalize

$.validator.methods.number = function (value, element) {
    return this.optional(element) || !isNaN(Globalize.parseFloat(value));
};

$(function () {
    Globalize.culture('pt-BR');
});

2-) Configured web.config

<globalization culture="pt-BR" uiCulture="pt-BR" />

Ok, so I´m using a JQuery plugin to format Textbox to Money(PT-BR) like that : 1.500.000,50...

My JQuery Client Validation is working fine! But when it goes to server validation I got a ModelState error:

"The value '1.500.000,50' is not valid for Total."

How can I fix that?

Thanks

like image 535
Paul Avatar asked Jul 07 '11 16:07

Paul


1 Answers

There is a problem in MVC binding to values like that. Go through this post by Phil Haack. It shows you how to create a cusom model binder to handle this.

like image 139
Eranga Avatar answered Oct 15 '22 13:10

Eranga