0

I'm using MVC3 + Razor.

I'm sending a parameter on a textbox to a Controller. I'm using the "es-AR" globalization.
I want a float number to have this format: "9,99" (comma as a decimal separator)

When I put a "comma separator" number in the textbox, the controller receives NULL on the "weight"variable. When I put a "dot separator", the weight float variable is OK.

View:

@Html.TextBox("weight")

(Basically, this is a search field. )

Controller:

 public ActionResult UserQueryPage(float? weight )

web.config:

  <system.web>
<globalization uiCulture="es" culture="es-AR" />

Is there anything else that I can do about it? Any tip?

Thanks!

1
  • <globalization uiCulture="es" culture="es-AR" /> should work. I am unable to reproduce the issue. Could you please post a full example including your controller and view allowing to illustrate the problem? By the way are you using AJAX? Commented Aug 15, 2012 at 15:57

1 Answer 1

1

The Default Model Binder doesn't take locale into account so the value with the comma will never bind correctly! You'll need a custom Model Binder for decimals http://haacked.com/archive/2011/03/19/fixing-binding-to-decimals.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

This seems to be the solution, I'll be testing it and getting back to you. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.