私は次のクラスを持っています。たとえば、それらは少し単純化されています。
class LineInfo
{
Id,
LineNumber,
SubAccountNumer,
MobileNumber
}
class SuspendLinesVM{
public List<LineInfo> Lines{ get;set; }
}
アクションで SuspendLinesVM を受け取り、すべての回線がクライアントから動的に作成されます。フォーム内の具体的な LineInfo に属する各要素には、テンプレート ' lineid{Id}_ElementName ' を使用した名前があります。したがって、それらは次のような形式で私に届きます。
lineid0001_LineNumber
lineid0001_SubAccountNumer
lineid0001_MobileNumber
lineid0021_LineNumber
lineid0021_SubAccountNumer
lineid0021_MobileNumber
検証中に何らかのエラーが発生した場合、失敗したプロパティを設定する方法が必要です。これは、ビューで無効なフィールドを強調表示する要求があったためです。
混乱したところに質問を残しました。
public class LineInfoValidator: AbstractValidator<LineInfo>
{
public LineInfoValidator()
{
RuleFor(m => m.LineNumber)
.NotEmpty().WithMessage("Line # is required").OverridePropertyName( ??? )
.InclusiveBetween(1, 9999).WithMessage("Line # must be in range [1, 9999]").OverridePropertyName( ??? )
...
*(instance, propertyName) => return string.format('lineid_{0}_{1}', instance.Id, propertyName)* のような方法が必要です。
何か案は ?