开发者

MVC 3 decimal server-side validation problem

开发者 https://www.devze.com 2023-03-18 13:23 出处:网络
I´m using JQuery Unobt开发者_运维百科rusive validation... I´m configured with Globalize to accept numbers like that : 1.500,50 (Masked by JQuery)

I´m using JQuery Unobt开发者_运维百科rusive 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号