如何从 TagHelper ModelExpression 中获取 MaxLength 属性?
我曾经能够在 MVC 5 中做到这一点
var member = expression.Body as MemberExpression;
var maxLength = member?.Member
.GetCustomAttributes(typeof(MaxLengthAttribute), false)
.FirstOrDefault() as MaxLengthAttribute;
我需要获取模型上的 MaxLength 属性 - 示例:
[MaxLength(5)]
[Display(Name = "First Name")]
public string FirstName { get; set; }
TagHelper 确实公开了 ModelExpression.Metadata。DisplayName属性和其他属性,但不是 MaxLength 或 StringLength 属性