The field Valor Pago must be a number. ASP NET MVC

Asked

Viewed 214 times

1

I own this field at Model:

public decimal Valor { get; set; }

It records correctly, and shows me the value in this way:

10,00

But when I edit, and complete the action, it returns to me :

The field Valor Pago must be a number.

I tried to add this script I saw in a tutorial to check if solved the problem, but still persists:

jQuery.extend(jQuery.validator.methods, {
   date: function (value, element) {
      return this.optional(element) || /^\d\d?\/\d\d?\/\d\d\d?\d?$/.test(value);
   },
   number: function (value, element)  
      return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
   }
});

HTML:

<div class="col-sm-3">
   <label asp-for="ContasReceberVM.ContasReceber.Valor" class="control-label"></label>
   <input asp-for="ContasReceberVM.ContasReceber.Valor" class="form-control" type="text" />
   <span asp-validation-for="ContasReceberVM.ContasReceber.Valor" class="text-danger"></span>
</div>
  • Copying code like this from the net and putting it to work in your code, not knowing what the code is really doing, is definitely not good practice. For example you saw that this code has an extra key lock?

  • It’s because I had put it inside a function to see if the problem could be, but it didn’t work anyway. I know it’s not good practice, but no way it works, so I have to take my chances with internet codes.

  • You know this is a plugin, do not know?

  • I know, but it didn’t work out. I tried a mask type and not right, I could not even convert type, because when you click the button, it already returns this error.

  • Post your entire model

No answers

Browser other questions tagged

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