Reputation: 61
I'm trying to insert a decimal number in one form but with no success. Everytime, I get this:
My entity is declared like this:
public class Serie
{
public int Id { get; set; }
public string Name { get; set; }
[RegularExpression(@"^\d+\.\d{0,2}$")]
[Range(0, 9999999999999999.99)]
public decimal Price { get; set; }
public string Description { get; set; }
public List<Season> Seasons { get; set; }
public List<Rental> Rentals { get; set; }
public List<Assessment> Assessments { get; set; }
}
On my razor page I have this on html side:
@page
@model Shows4All.Pages.Series.CreateModel
@{
ViewData["Title"] = "Create";
}
<h1>Create</h1>
<h4>Serie</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Serie.Name" class="control-label"></label>
<input asp-for="Serie.Name" class="form-control" />
<span asp-validation-for="Serie.Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Serie.Price" class="control-label"></label>
<input type="number" asp-for="Serie.Price" class="form-control" />
<span asp-validation-for="Serie.Price" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Serie.Description" class="control-label"></label>
<input asp-for="Serie.Description" class="form-control" />
<span asp-validation-for="Serie.Description" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-page="Index">Back to List</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
I already tried without Data annotation and withou type="number" on html side...but it doesn't work. Any idea how can it be solved?
Upvotes: 0
Views: 820
Reputation: 464
Try to add locale configuration in your aspet.config file like this:
<configuration>
<system.web>
<globalization culture ="en-US" />
</system.web>
</configuration>
If didn't work, try remove the Regex attribute and test it again.
Upvotes: 1