结合 ViewModel (WPF/Silverlight) 和强类型 ViewData (ASp.NET MVC)?
注意:在下面的文本中,我将使用术语“ViewModel”来表示 WPF/Silverlight 中的 ViewModel 和 ASP.Net MVC 中的强类型 ViewData。
我想为同一个项目(换句话说,针对同一个 DataModel)创建 ASP.Net MVC 和 WPF/Silverlight 客户端,我应该为每个客户端技术创建一个公共 ViewModel 项目还是单独的 ViewModel ?
我相信通用 ViewModel 是正确的做法,但创建依赖属性或 JSON 字符串的需要使其看起来不兼容。
也许另一种解决方案是将ViewModel的公共部分放入DataModel层?
我将不胜感激任何帮助我走向正确方向的帮助,谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 Silverlight 项目无法引用非 Silverlight 项目的限制(由 Visual Studio 强加),您将需要单独的 ViewModel(尽管有一两个已记录的 hack 可以解决该问题)。
您可以在两个项目之间共享代码,方法是在一个项目中包含物理类,然后将现有项目添加到第二个项目(导航到原始类,然后选择原始类,然后单击“添加为链接”)。小提示:如果您认为一个类将以这种方式共享,请尽可能保持命名空间中立,这样可以避免混乱和/或进一步重构。
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.