Resuse ViewModel in Asp.net MVC

倖福魔咒の 提交于 2019-12-11 03:18:00

问题


I have seen lots of blog about MVVM vs MVC and blogs that says thay MVVM is like MVC extension in Windows.

I have one design issue, I have made one win application that uses MVVM , now i have to create a same application in Web, so i decided to MVC pattern in Asp.net, but now again i am stuck at point.

how to reuse ViewModels in MVC? because ViewModel has imports namespace System.Windows.Input.

Is there any alternative soultions?? My primary requirement is reusing application logic?

I have used http://waf.codeplex.com/ WpfApplication framework as refrence.

Thanks in advance.


回答1:


The fact is that the two aren't interchangeable. Nor are they supposed to be (in a practical sense). Yes, you could create ViewModels that could also be reused in ASP.NET MVC. But the amount of abstraction you would have to incorporate would make the exercise useless.

You should not waste your time worrying about this incompatibility, working hard to reduce/eliminate it.

What you should do is move truly reusable code that has no dependencies on either WPF or ASP.NET into reusable libraries. This code is what should be reused in both applications. Your ViewModels and Controllers belong with the application frameworks they were designed to service.




回答2:


Your business logic should be in your Models, not in your View Models. So it's the Models you want to reuse, nothing else. View Models are specific to your Windows application, and are equivalent to Controllers which are specific to a web application.



来源:https://stackoverflow.com/questions/6816007/resuse-viewmodel-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!