MVC:在十进制参数中传递货币的问题 [英] MVC: Problems to pass currency in decimal parameter

查看:52
本文介绍了MVC:在十进制参数中传递货币的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将货币值传递给十进制属性,但是MVC删除了,".我尝试使用.",但是MVC也删除了.

I'm trying pass a currency value to a decimal property, but the MVC removes the ",". I tried with ".", but the MVC removes too.

public ActionResult MyAction(decimal value)
{
}

我正在将ajax请求发送到以下URL:

I'm sending the ajax request to the following URL:

/MyAction?value = 1000,35

/MyAction?value=1000,35

但是,当我发送请求时,我收到了100035的值.为什么?

But when I send the request, I received the 100035 value. Why?

推荐答案

要解决我的问题,我使用了这篇文章:

To resolve my problem, I used this article:

http://haacked.com/archive/2011/03/19/fixing-binding-to-decimals.aspx/

我创建了一个如文章所示的DecimalModelBinder

I created one DecimalModelBinder like the article shows

我要做的另一件事是在将小数转换为字符串之前将其付诸行动:

Another thing that I did is converting the decimal to string before to send to action:

var url = string.Format("/MyAction?value={0}", decimalValue);

这篇关于MVC:在十进制参数中传递货币的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆