【发布时间】:2021-05-10 23:30:32
【问题描述】:
我正在使用 Razor 页面和内置 CRUD 页面构建应用程序。我有一个使用 SQL Express 的代码优先设置,在我的 Location 表中我有一个可以为空的 int col,名为“Phone”。我的位置类非常简单
[Column("Phone")]
public Nullable<int> Phone { get; set; }
我的 Context 类也很简单
public DbSet<Location> Location { get; set; }
我的自动生成的 CRUD 编辑页面看起来像
<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" />
我没有看到我告诉 VS 这是电话格式,除电话号码外,其他所有内容都会保存。当我将任何内容放入 5554443333 或其他任何内容时,我得到:“值 '5554443333' 对电话无效。”从 asp 验证。如果我将电话字段留空,则其他所有内容都会正确保存。稍后我会加入一些正则表达式来处理破折号、括号和空格。我只需要帮助找到如何关闭或降低此字段的验证。
提前致谢。
【问题讨论】:
标签: c# asp.net-core .net-core crud razor-pages