1

我最近下载/安装了 WATK。我还注册了免费的 azure 试用版。完成了实验室“使用 Windows Azure 网站和 Visual Studio 2012 构建和发布 ASP.NET 应用程序”。当我发现该工具包使用 .NET 4.5 并且 Azure 站点只接受 .NET Framework 4.0 时,我完成了 80%。如果我将实验室属性配置更改为 4.0,它将无法编译。罪魁祸首代码是:

[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]

[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
4

2 回答 2

2

The issue you're having here is because the CompareAttribute attribute is both available in the 4.5 version of the DataAnnotations assembly and in the System.Web.Mvc assembly. Since you started the project in 4.5 you probably based your code on System.ComponentModel.DataAnnotations.CompareAttribute (.NET 4.5).

By switching to the System.Web.Mvc.CompareAttribute you can fix the error:

[System.Web.Mvc.CompareAttribute("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]

[System.Web.Mvc.CompareAttribute("Password", ErrorMessage = "The password and confirmation password do not match.")]

(Adding a using statement for System.Web.Mvc will also fix the issue)

于 2012-09-14T09:29:25.743 回答
1

该实验室从 File>New Project 开始,因此在您执行 File>New 之前,它并没有真正绑定到框架。检查对话框上的默认框架,我怀疑它是 4.5

在此处输入图像描述

至于事后将其更改回 4.0,我没有尝试过,但可能生成的其他代码不兼容。您提到的两行绝对是生成代码的一部分,在我的情况下不会引起问题。

相关的编译错误是什么?

于 2012-09-14T07:00:37.277 回答