Set monetary value field correctly in Asp.Net MVC

Asked

Viewed 143 times

0

I am having problems with monetary value in my Asp.Net MVC application and would like to know how to set up

In class

[Display(Name = "Valor Produto")]
[Required(ErrorMessage = "O campo {0} é obrigatório")]
[DataType(DataType.Currency)]
public float AnuncioValorProduto { get; set; }

At View I switched to Texboxfor

<div class="form-group">
    @Html.LabelFor(model => model.AnuncioValorProduto, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.TextBoxFor(model => model.AnuncioValorProduto, new { htmlAttributes = new { @class = "form-control" } })
        @Html.ValidationMessageFor(model => model.AnuncioValorProduto, "", new { @class = "text-danger" })
    </div>
</div>

I downloaded the script jquery-maskmoney

I put the scripts in the folder and added them to Bunddleconfig.Cs

 bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*",
                        "~/Scripts/jquery.maskMoney.js"));

And this giving the following error as shown below Erro campo monetário

And initialized the command with jquery as documentation

<script>
    $(function () {
        $('#AnuncioValorProduto').maskMoney();
    });
</script>
  • 1

    The first problem, and very serious, is to use float for monetary value. https://answall.com/a/230639/101

  • @Maniero already switched to decimal, now what I must do to continue the configuration, because I realize that this inverted (,) and (.)

No answers

Browser other questions tagged

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