A Bogus
A Bogus

Reputation: 3920

Is it bad practice to have a View Model with methods in it that fill the View Model

For a .Net MVC application, is it bad practice to have a View Model with methods in it that fill the View Model such as this -

public class MyViewModelClass
{
   public string MyProperty1 { get; set; }
   public string MyProperty2 { get; set; }
   public string GetProperties()
   {
       this.MyProperty1 = DataRetriever.GetProperty1();
       this.MyProperty2 = DataRetriever.GetProperty2();

   }
}

Can this cause problems in MVC such as with posting from the view?

Upvotes: 1

Views: 114

Answers (1)

user
user

Reputation: 719

Yes it is considered bad practice. A view model should be a DTO that contains no logic but only transport data

Upvotes: 1

Related Questions