我正在嘗試創建一個注冊頁面,如果用戶正在積極作業,我想要求作業詳細資訊(公司名稱、職位等)部分。但是找不到解決辦法
![僅當上述條件為真時,我才嘗試制作標簽 [必需]](https://img.uj5u.com/2022/04/01/0fb4a0db70534fefa749d14867d8baee.png)
uj5u.com熱心網友回復:
我會說你在你的模型中實作了一個看起來有點像這樣的驗證器。
public class YourModelClassName : IValidatableObject
{
// Loads of properties Name, Phone yada yada...
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (EmployeeActive == true
&& String.IsNullOrEmpty(CompanyName)
&& String.IsNullOrEmpty(Position)
// add more if needed
)
{
yield return new ValidationResult(
// some message here.
$"When you are an active employee you must fill in the basic data for your employment...",
new[] { nameof(EmployeeActive) });
}
}
}
在此處閱讀更多資訊:https ://docs.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-6.0#ivalidatableobject
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/453505.html
標籤:C# asp.net-mvc asp.net-mvc-5
上一篇:從多對多關系表中查詢
