开发者

ASP.NET MVC 3 ViewModels in a different project?

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 fr开发者_开发百科om the website code.


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.


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 :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜