vs2022 mvc6.0
他のカラムは、空白にした状態で登録しようとすると標準のエラーメッセージが表示されるが、parent_codeカラムはエラーメッセージが表示されず困っています。
scaffoldしてなにもいじってない状態でも反映されていませんでした。
edit.cshtml <div asp-validation-summary="ModelOnly" class="text-danger"></div> <input type="hidden" asp-for="Id" /> <div class="form-group"> <label asp-for="Grp" class="control-label"></label> <input asp-for="Grp" class="form-control" /> <span asp-validation-for="Grp" class="text-danger"></span> </div> <div class="form-group"> <label asp-for="Dept" class="control-label"></label> <input asp-for="Dept" class="form-control" /> <span asp-validation-for="Dept" class="text-danger"></span> </div> <div class="form-group"> <label asp-for="Code" class="control-label"></label> <input asp-for="Code" class="form-control" /> <span asp-validation-for="Code" class="text-danger"></span> </div> <div class="form-group"> <label asp-for="Name" class="control-label"></label> <input asp-for="Name" class="form-control" /> <span asp-validation-for="Name" class="text-danger"></span> </div> <div class="form-group"> <label asp-for="LotPattrern" class="control-label"></label> <input asp-for="LotPattrern" class="form-control" /> <span asp-validation-for="LotPattrern" class="text-danger"></span> </div> <div class="form-group"> <label asp-for="RoomIds" class="control-label"></label> <input asp-for="RoomIds" class="form-control" /> <span asp-validation-for="RoomIds" class="text-danger"></span> </div> <div class="form-group form-check"> <label class="form-check-label"> <input class="form-check-input" asp-for="SubFlag" /> @Html.DisplayNameFor(model => model.SubFlag) </label> </div> <div class="form-group"> <label asp-for="ParentCode" class="control-label"></label> <input asp-for="ParentCode" class="form-control" /> <span asp-validation-for="ParentCode" class="text-danger"></span> </div>
model using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace nk_web.Models { public partial class MWorkschedule { public int Id { get; set; } [Required(ErrorMessage = "グループは必須入力です。")] [Display(Name = "グループ")] public int Grp { get; set; } [Required(ErrorMessage = "部署は必須入力です。")] [Display(Name = "部署")] public int Dept { get; set; } [Required(ErrorMessage = "工程コードは必須入力です。")] [Display(Name = "工程コード")] public string Code { get; set; } = null!; [Required(ErrorMessage = "工程名は必須入力です。")] [Display(Name = "工程名")] public string Name { get; set; } = null!; [Required(ErrorMessage = "ロット工程パターンは必須入力です。")] [Display(Name = "ロット工程パターン")] public int? LotPattrern { get; set; } [Required(ErrorMessage = "作業室は必須入力です。")] [Display(Name = "作業室")] public string? RoomIds { get; set; } [Required(ErrorMessage = "サブ工程フラグは必須入力です。")] [Display(Name = "サブ工程フラグ")] public bool SubFlag { get; set; } [Required(ErrorMessage = "親工程コードは必須入力です。")] [Display(Name = "親工程コード")] public string? ParentCode { get; set; }
エラー内容 SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
ParentCodeのRequierdを消すとエラーは解除されます。
回答1件
あなたの回答
tips
プレビュー