好的,所以我有一个看起来像这样的模型:
public class CustomerViewModel {
public string Password { get; set; }
}
public class CustomerAddViewModel {
public CustomerViewModel Customer { get; set; }
[System.ComponentModel.DataAnnotations.Compare("Customer.Password", ErrorMessage = "The confirm password should match")]
public string ConfirmPassword { get; set; }
}
我在验证时收到错误消息“找不到名为 Customer.Password 的属性”。
我找到了这个 SO Question,但它不适用,因为在最新版本的validation.unobtrusive 中,代码如下所示:
element = $(options.form).find(":input[name='" + escapeAttributeValue(fullOtherName) + "']")[0];
其中 escapeAttributeValue 处理所有有效的特殊字符。
我尝试改用 System.Web.Mvc.Compare,但这会在渲染视图时导致错误。
有任何想法吗?