MVC 3位服务器端验证问题

MVC 3位服务器端验证问题

问题描述:

I'm ... I'm全球化时代与配置为接受这样的数字:1.500,50(的jQuery屏蔽)

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

我的code到目前为止

My code so far

1)全球化时代已配置

1- ) Configured Globalize

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

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

2-)配置的web.config

2-) Configured web.config

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

好了,I'm使用jQuery插件,以文本框格式化为货币(PT-BR)这样的:1.500.000,50 ...

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

我的JQuery客户端验证工作正常!但是,当它进入服务器验证我得到的ModelState错误:

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?

感谢

有在MVC结合这样的价值观有问题。通过由菲尔哈克这个帖子。它表明你如何创建一个cusom模型绑定来处理这个问题。

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.