Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Can I use same Model for MVVM and ASP.Net MVC?

$
0
0

Hi,

More I read about MVC and MVVM, and their connection, more I get confused. All I want is to use same Model for MVVM and MVC applications I am currently developing in WPF and ASP.Net MVC respectively. But when I checked samples of both patterns, the Model looks different. For example, a Model in MVVM is

public class User : NotifyObject
{
    private int _id;
    private string _loginId, _name, _email, _password;

    public Int32 Id
    {
        get { return this._id; }
        set
        {
            this._id = value;
            this.OnPropertyChanged("Id");
        }
    }
    public string LoginId
    {
        get { return this._loginId; }
        set
        {
            this._loginId = value;
            this.OnPropertyChanged("LoginId");
        }
    }
    public string Password
    {
        get { return this._password; }
        set
        {
            this._password = value;
            this.OnPropertyChanged("LoginId");
        }
    }
    public string Name
    {
        get { return this._name; }
        set
        {
            this._name = value;
            this.OnPropertyChanged("Name");
        }
    }
    public string Email
    {
        get { return this._email; }
        set
        {
            this._email = value;
            this.OnPropertyChanged("Email");
        }
    }
}

However, a Model in ASP.Net MVC looks like

public class LogOnModel
{
        [Required]
        [DisplayName("Login name")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.Password)]
        [DisplayName("Password")]
        public string Password { get; set; }

        [DisplayName("Remember me?")]
        public bool RememberMe { get; set; }
}

Model in ASP.Net MVC looks like ViewModel to me. My questions are -

1. Are Models in MVVM and ASP.Net MVC same? Can I use same Model in MVVM and MVC?
2. Where should I implement System.ComponentModel.DataAnnotations in MVVM? ViewModel or Model?
3. Should I create same properties in ViewModel and Model both or should I expose Model to View from ViewModel?

Thank you for your patience.

Ritesh


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>