好了,所以我有一個模型,看起來像:ASP.NET MVC 4不顯眼的確認上破複雜的模型
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屬性,您將收到錯誤消息。有一個密碼屬性,但它坐在不同的類 –