Hi, I have been learning ASP.NET MVC for few months. I have learned about view, controllers and models and stuff. To design a view we always need a model, Usually a model is a just a class which we fill with data and pass to a view. I have a question here should model itself do some calculation or it should be just dumb.
For example I have a site where I load books by Users. My model class is as follows:
public class FormViewModel
{
public User MyUser {get; set;}
public Books UserBooks {get; set;}
//Constructor here.
public FormViewModel(User _user, Books _userBooks)
{
this.MyUser=_user;
this.UserBooks=_userBooks;
}
}
This class doesn't do anything, just a template. Now if I modify the code and write as follows:
public class FormViewModel
{
public User MyUser {get; set;}
public Books UserBooks {get; set;}
//Constructor here.
public FormViewModel(User _user)
{
this.MyUser=_user;
this.UserBooks=_user.GetBooks();
}
}
In here books are collected depending on what user has been selected. Now its much easier to work with.
I just want to know what is a good approach according to MVC patterns and practices.
Help from the experts will be greatly appreciated.
Regards Parminder