Miraj Baldha
Miraj Baldha

Reputation: 307

Resuse ViewModel in Asp.net MVC

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.

Upvotes: 2

Views: 799

Answers (2)

Tim Rogers
Tim Rogers

Reputation: 21713

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.

Upvotes: 2

user1228
user1228

Reputation:

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.

Upvotes: 5

Related Questions