Answer the question
In order to leave comments, you need to log in
Entity framework validation for decimal type. How can I make it skip a fractional value?
If separated by commas, then on the client:
The field Amount must be a number.
The value '123.5' is not valid for Sum
[DisplayName("Сумма")]
public decimal Sum { get; set; }
<div class="form-group">
@Html.LabelFor(model => model.Sum, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Sum, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Sum, "", new { @class = "text-danger" })
</div>
</div>
Answer the question
In order to leave comments, you need to log in
For editing, use the string type . Convert to decimal before saving to base .
In my projects I use an auxiliary class that has methods for working with numbers and can understand any decimal separator. Specifically, for this situation, there is a ToDecimal method (the code is open, the license does not prohibit using it in parts, if that).
[DisplayName("Сумма")]
public string Sum { get; set; }
public decimal SumDec
{
get
{
return Convertion.ToDecimal(this.Sum);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question