简体   繁体   English

具有单独的模型装配项目的MVC 3,EF4自定义远程验证

[英]MVC 3, EF4 Custom Remote Validation with separate model assembly project

I have setup an MVC3 EF4 project with Model and the Repository broken off in to separate assembly projects. 我已经建立了一个MVC3 EF4项目,其中的Model和Repository被分解为单独的组装项目。 The basic validation for a required property etc. works fine, but if i need to do any remote validation say to check if a user is already in a group, etc. The remote validation does not recognize the controller within the Model project. 所需属性等的基本验证工作正常,但是如果我需要执行任何远程验证,请说要检查用户是否已经在组中,等等。远程验证无法识别Model项目中的控制器。

[Remote("IsUID_Available", "Validation")]

When I try to add a reference to the main project inside the Model project it says it would cause a circular dependency and doesn't allow it to be added. 当我尝试在Model项目中添加对主项目的引用时,它说这将导致循环依赖,并且不允许添加。

Do I need to move my Models out the separate assembly and into the main project or is there another way to do remote validation with the Models being in a separate assembly. 我是否需要将模型移出单独的程序集并移至主项目中,还是有另一种方法可以使模型位于单独的程序集中进行远程验证?

Also what is the best practice here. 另外,这里的最佳做法是什么。 I've read several articles that say putting the models in a separate assembly is the best practice but if you can't use half the validation functionality of MVC what is the point. 我读过几篇文章说,将模型放在单独的组件中是最佳实践,但是如果您不能使用MVC的一半验证功能,那是什么意思。 I've also noticed most of the Microsoft MVC samples show the models just in the main project and not broken off into an assembly. 我还注意到,大多数Microsoft MVC样本仅在主项目中显示模型,而没有分解为组件。

Turns out this wasn't an issue after all. 原来,这根本不是问题。 Remote validation can be used as specified in the code above with the model in a separate assembly. 可以按照上面的代码中的指定,在单独的程序集中与模型一起使用远程验证。

It was ReSharper that was giving an error in visual studio that the controller was unknown and marking it with the red underline but when actually compiled and tested the remote validation works. 正是ReSharper在Visual Studio中给出了一个错误,即控制器未知,并用红色下划线标记了该控制器,但是在实际编译和测试远程验证时有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM