我正在MVC3中创建应用程序。在创建应用程序,有在Web项目中创建三个文件夹:将mvc 3中的模型从web项目移动到类库
- 控制器
- 模型
- 查看
我想实现一个分层architechture,所以我创建了一个类库项目将具有业务和存储库层。
我将模型从Web项目移至类库项目,以便我可以在业务层中使用模型。 模型类含有以下所示规定的所要求的性质和它们的验证:
public class ChangePasswordModel
{
[Required]
[DataType(DataType.Password)]
[Display(Name = "Current password")]
public string OldPassword { get; set; }
[Required]
[ValidatePasswordLength]
[DataType(DataType.Password)]
[Display(Name = "New password")]
public string NewPassword { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm new password")]
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}
public sealed class ValidatePasswordLengthAttribute : ValidationAttribute, IClientValidatable
我也有在同一文件中的类以上,以验证它实现IClientValidatable
我面临两个接口我的密码长度问题:
- 我无法使用CompareAttribute以及接口
IClientValidatable
。这两个类都是System.Web.MVC的一部分。我已将System.Web.MVC
dll的引用添加到我的类库中。
在这两种情况下,我无法解决问题。 resharper提到有关循环依赖的错误。
我可以不使用System.Web.Mvc
引用并使用类库中提供的类和验证吗? 此外,System.ComponentModel.DataAnnotations
中提供的验证不会产生问题。
我无法构建解决方案,因此无法继续开发。 欢迎任何解决方案和建议。
你应该花更多的时间,如果你想帮助格式化你的问题。我这次做了。 – jgauffin 2012-05-04 14:16:40