こんにちは、アプリ全体に次のタラがありますが、2 つのフィールドだけでは機能しません。
[Required]
public string DevelopmentPM { get; set; }
次のテストが実行され、合格します。
[TestMethod]
public void SiteConstruction_MODEL_DevelopmentPM_Is_Required()
{
//arrange
var propertyInfo = typeof(SiteConstructionMetadata).GetProperty
("DevelopmentPM");
//act
var attribute = propertyInfo.GetCustomAttributes(typeof(RequiredAttribute),
true).Cast<RequiredAttribute>().FirstOrDefault();
//assert
Assert.IsNotNull(attribute);
}
私のコントローラーは次のようになります。
TryUpdateModel(siteConstruction);
if (!ModelState.IsValid)
return View(siteConstruction);
モデルに他の必須フィールドがありますが、それらは問題ありません。このフィールドは null (チェック済み) ですが、モデルが無効になることはありません。そのため、検証が行われず、保存時にエラーが発生します。
私の見解
<li>
<label for="DevelopmentPM">
<strong>Development PM:</strong></label>
<%= Html.TextBox("DevelopmentPM") %>
<%= Html.ValidationMessage("DevelopmentPM", "*") %>
</li>
私は自分の .dbml (Linq to SQl) を見てきましたが、スペルは問題ないようです。
私は何か単純なものを見逃しています - どうぞ、怒ってください。
ありがとう
デービー