ASP.NET MVC: Model Binding problem

Asked

Viewed 46 times

0

I’m passing an object that has following property to Action:

{
    ...
    Valor : "3500.00"
}

Financapessoalviewmodel:

public class FinancaPessoalViewModel
{
    ...
    public decimal Valor { get; set; }
}

Action:

[HttpPost]
public ActionResult AdicionarLancamento(FinancaPessoalViewModel financa)
{
    var errors = ModelState.Values.SelectMany(v => v.Errors);
    //The value '3500.00' is not valid for Valor.
    ...
}

It is always coming 0 to the property "Value", he is unable to do Binding. How to fix this?

  • 2

    If you pass the value as 3500,00 (comma) it works?

  • 1

    This is different culture problem, for sure if you pass ',' instead of point as told by our friend jbueno will work. And you can get around that by using this reply =]

  • Oh yes, thanks guys! That’s right. I didn’t understand because C# only "understood" decimal with a dot, and not with a comma.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.