'asp.net Core Razor CRUD - wont accept any input for Phone as valid
I'm building an app using Razor pages and the built in CRUD pages. I have a code-first setup with SQL Express and in my Location table I have a nullable int col named 'Phone'. My Location Class is very straight forward with
[Column("Phone")]
public Nullable<int> Phone { get; set; }
and my Context class is simple too
public DbSet<Location> Location { get; set; }
My auto generated CRUD Edit page looks like
<input asp-for="Location.City" class="form-control" />
<span asp-validation-for="Location.City" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Location.State" class="control-label"></label>
<input asp-for="Location.State" class="form-control" />
<span asp-validation-for="Location.State" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Location.Zip" class="control-label"></label>
<input asp-for="Location.Zip" class="form-control" />
<span asp-validation-for="Location.Zip" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Location.Phone" data-val="false" class="control-label"></label>
<input asp-for="Location.Phone" data-val="false" class="form-control" />
<span asp-validation-for="Location.Phone" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
I don't see that I told VS this is a Phone format and everything else saves except for the phone number. When I put anything in 5554443333 or whatever, I get: "The value '5554443333' is not valid for Phone." from asp-validation. If I leave the phone field blank, everything else saves properly. I'll put in a little regEx to handle dashes, parenthesis, and spaces later. I just need help in finding how to either turn off or tone down the validation for this field.
Thanks in advance.
Solution 1:[1]
Because the range of int type is -2,147,483,648 to 2,147,483,647, and your input has exceeded this range, it is recommended that you use string or long type.
[Column("Phone")]
public string? Phone { get; set; }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
