【发布时间】:2013-08-06 18:07:11
【问题描述】:
好的,所以我有一个看起来像这样的模型:
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 的属性”。
我找到了this SO Question,但它不适用,因为在最新版本的validation.unobtrusive 中,代码如下所示:
element = $(options.form).find(":input[name='" + escapeAttributeValue(fullOtherName) + "']")[0];
其中 escapeAttributeValue 处理所有有效的特殊字符。
我尝试改用 System.Web.Mvc.Compare,但这会在渲染视图时导致错误。
有什么想法吗?
【问题讨论】:
-
您收到错误是因为没有 Customer.Password 属性。有一个 Password 属性,但它位于不同的类中
标签: asp.net-mvc asp.net-mvc-4 jquery-validate unobtrusive-validation data-annotations