ASP.NET MVC: Problem when assigning decimal value

Asked

Viewed 760 times

0

Fichaviewmodel.Cs

[Required(ErrorMessage = "A altura é obrigatória.")]
public decimal Altura { get; set; }

fiche.js

$("#Altura").mask("9.99");

Fichacontroller.Cs

[HttpPost]
public ActionResult Cadastro(FichaViewModel fichaView)
{
    if (ModelState.IsValid)
    {
       ...
    }

    return View(fichaView);
 }

Value '1.70' is not valid for Height.

How do I make the Height accept the past value?


When leaving the mask with comma (9.99) the validation recognizes as text, and with dot (9.99) gives the error as mentioned. So I decided to leave the Property as string and when mapping from Fichaviewmodel to Fichadomain, with Automapper, the conversion normally occurs.

  • Rafael, a while ago I asked this question: What is the correct way to use the float, double and decimal types?

  • Hello @Marconi! So I’ve tested double too, but the problem is the same.

  • Checks whether the variable fichaViewis receiving the Altura straight.

  • It receives the value 0, but when I see in the Modelstate errors, the message that gives is the one I mentioned.

No answers

Browser other questions tagged

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