Renato Leite
Renato Leite

Reputation: 791

MVC: Problems to pass currency in decimal parameter

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)
{
}

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

/MyAction?value=1000,35

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

Upvotes: 7

Views: 1552

Answers (1)

Renato Leite
Renato Leite

Reputation: 791

To resolve my problem, I used this article:

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

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);

Upvotes: 2

Related Questions