views:

121

answers:

1

Note: I will use the term "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

+1  A: 

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.

slugster
Thanks for the reply. But you're talking about a different issue. Probably I should not mention Silverlight, just some code reuse technology for the ViewModel between ASP.NET MVC and WPF.
Nan Li