Solved

MVVM Pattern in asp.net web application

Posted on 2010-09-15
12
1,089 Views
Last Modified: 2013-11-07
Hi

I have a web application in which I want to implement MVVM pattern. I want to know if there any sample code that will clearly mention what all steps I need to execute to implement it.


Apart from that I want to know if there is any dll that need to be refered.

Kindly advice

Regards
Karan Gupta
0
Comment
Question by:KaranGupta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 200 total points
ID: 33681349
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33681399
0
 

Author Comment

by:KaranGupta
ID: 33688365
Hi

I am trying to implement the code(please check the code section).  I am getting the compile time error

1. INotifyPropertyChanged is not defined.
2. Application is not declared
3. Type PropertyChangedEventHandler is not defined.

Is there any namespace that I am missing,

Regards
Karan Gupta
Imports Microsoft.VisualBasic

Public Class ViewModelBase
    Inherits INotifyPropertyChanged

    Protected Sub OnNotifyPropertyChanged(ByVal p As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(p))
    End Sub

    Public ReadOnly Property IsDesignTime() As Boolean
        Get
            Return (Application.Current Is Nothing) OrElse (Application.Current.[GetType]() = GetType(Application))
        End Get
    End Property

#Region "INotifyPropertyChanged Members"
    Public Event PropertyChanged As PropertyChangedEventHandler
#End Region


End Class

Open in new window

0
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 300 total points
ID: 33688856
0
 

Author Comment

by:KaranGupta
ID: 33698708
Hi

I have included System.ComponentModel namespace but still I am getting the same error. Please check the code attached.


Regards
Karan Gupta

Imports Microsoft.VisualBasic
Imports System.ComponentModel


Public Class ViewModelBase
    Inherits INotifyPropertyChanged

    Protected Sub OnNotifyPropertyChanged(ByVal p As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(p))
    End Sub

    Public ReadOnly Property IsDesignTime() As Boolean
        Get
            Return (Application.Current Is Nothing) OrElse (Application.Current.[GetType]() = GetType(Application))
        End Get
    End Property

#Region "INotifyPropertyChanged Members"
    Public Event PropertyChanged As PropertyChangedEventHandler
#End Region


End Class

Open in new window

0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 300 total points
ID: 33698760
0
 

Author Comment

by:KaranGupta
ID: 33698875
Hi

As the tutorial given in

http://weblogs.asp.net/dwahlin/archive/2009/12/08/getting-started-with-the-mvvm-pattern-in-silverlight-applications.aspx

there has to be View, Model and View Model that is what MVVM pattern is all about. If I am making a contact us page then I have a textbox. In the view i.e. .aspx page I will put all the UI part. In the view model it should be properties . When it comes to Business logic out all the logic in the Model.

I have some queries

1. Is what I have written is correct?
2. View model should be inherited from ViewModelBase class. Am I right(Please check code section)?
3. Is the model class should be inherited from some class?

Kindly advice

Regards
Karan Gupta
Imports System.ComponentModel

Public Class ViewModelBase
    Implements INotifyPropertyChanged

    Public Event PropertyChanged As PropertyChangedEventHandler _
        Implements INotifyPropertyChanged.PropertyChanged

    Private Sub NotifyPropertyChanged(ByVal info As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    End Sub
End Class

Open in new window

0
 

Author Comment

by:KaranGupta
ID: 33698977
Hi

Can we application MVVM pattern in simple asp.net application without using silverlight?


Regards
Karan Gupta
0
 

Author Comment

by:KaranGupta
ID: 33713646
Hi

Any updates?

Regards
Karan Gupta
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 300 total points
ID: 33714071
0
 
LVL 29

Assisted Solution

by:Gautham Janardhan
Gautham Janardhan earned 200 total points
ID: 33714105
MVVM was designed keeping Silver light /  WPF in mind so i don't think you will be able to utilize it in Asp.net. You may either look into MVP as Dhaest suggested  or better go for MVC
0
 

Author Closing Comment

by:KaranGupta
ID: 33751106
Query resolved
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question