开发者

Combine ViewModel (WPF/Silverlight) and strongly-typed ViewData (ASp.NET MVC)?

Note: I will use the t开发者_运维知识库erm "ViewModel" for both the ViewModel in WPF/Silverlight and the strongly-typed ViewData in ASP.Net MVC in the following text.

I would like to create both ASP.Net MVC and WPF/Silverlight clients for the same project (in other words, against the same DataModel), should I create a common ViewModel project or a separate ViewModel for each client technology?

I would like to believe a common ViewModel is the right thing to do, but the need to create Dependent Properties or JSON strings make it seem to be incompatible.

Maybe another solution is to put the common part of the ViewModel into the DataModel layer?

I'll appreciate any help that would put me in the right direction, thanks


You will need separate ViewModels due to the restriction (imposed by Visual Studio) that a Silverlight project cannot reference a non-Silverlight project (although there are one or two documented hacks to work around that).

You can share code between the two projects by having the physical class in one project, and then adding an existing item to the second project (navigate to and then select the original class, then click 'Add as link'). Small hint: if you think a class is going to be shared in this way, keep the namespace as neutral as possible, it can save confusion and/or refactoring further down the track.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜