ASP.NET MVC 3 ViewModels 在不同的项目中?

发布于 2024-10-07 11:23:40 字数 165 浏览 0 评论 0原文

有什么可以阻止您将 ViewModel 放置在不同的项目中吗?

我基本上有一个 DataModel(实体框架)项目、数据访问项目(可能会将其合并到 DataModel 中)、业务逻辑项目和 ASP.NET MVC 网站。我希望业务逻辑层返回 ViewModel,因此想知道这些是否可以与网站代码分开。

Is there anything from stopping you placing ViewModels in a different project?

I basically have a DataModel (Entity Framework) project, Data Access project (might merge this into the DataModel), Business Logic project and the ASP.NET MVC website. I want the Business Logic layer to return ViewModels so was wondering if these can be separate from the website code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听风吹 2024-10-14 11:23:40

绝对可以 - 您只需要在 MVC3 项目中引用 DLL,然后在强类型视图中引用这些 ViewModel。

只需确保您

@model SeperateAssembly.ViewModelName

在视图顶部声明,以使它们成为强类型。

Absolutely - you just need to reference the DLL in your MVC3 project and then reference those ViewModels in your strongly typed views.

Just make sure you declare

@model SeperateAssembly.ViewModelName

At the top of your views to make them strongly typed.

淡忘如思 2024-10-14 11:23:40

简短的回答:没有

长的回答:没有理由。这将使您必须更多地考虑项目引用和位的依赖关系。当涉及到参考资料等时,您只需要小心设计即可。

希望有所帮助。

另外,可以帮助进行单元测试:-)

Short answer : no

Long answer : no reason. It will make you have to think more about dependencies of project references and bits. You'll just have to be careful with the design when it comes to references etc.

Hope that helps.

Also, can help with unit testing :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文