Data Annotation with Real Values

Asked

Viewed 125 times

0

I have the following model:

[Display(Name = "Valor")]
[DataType(DataType.Currency)]
public decimal Valor { get; set; }

View:

<div class="form-group">
  @Html.LabelFor(m => m.Valor, "Valor", htmlAttributes: new { @class = "control-label" })
  <div class="input-group">
     <span class="input-group-addon"><i class="fa fa-money"></i></span>
     @Html.EditorFor(m => m.Valor, new {htmlAttributes=new {@class="money form-control"}})
     @Html.ValidationMessageFor(m => m.Valor, "", new { @class = "text-danger" })
</div>

In web.config you have the following configuration:

 <system.web>

 <globalization culture="pt-BR" uiCulture="pt-BR" />

 </system.web>

When doing the post Modelstate.Isvalid presents the following error:

The value '1.500,00' is not Valid for Valor.

  • What do you call "not working"? What happens and what you expect?

  • When I put thousand values like 1,500.00 the datamodel.isvalid returns false and informs that the value is not valid.

  • 1

    You should probably find what you want in the answers of this question.

No answers

Browser other questions tagged

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