2021年2月6日星期六

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.

https://stackoverflow.com/questions/66083338/asp-net-core-razor-crud-wont-accept-any-input-for-phone-as-valid February 07, 2021 at 08:18AM

没有评论:

发表评论