Reputation: 1729
I am learning ASP.NET MVC and looking at the ASP.NET MVC sample application NerdDinner.
The folder "Models" contains a class called Dinner.cs
. This is the main Dinner entity.
Shouldn't this class be in an other location? For example "Domain" ? And instead should a viewmodel class be put in the Models folder that contains dinner information?
Why is the file "PaginatedList.cs" located in the folder called: "Helpers". Shouldn't this file be in the folder: "Models" since it is supplied to views?
Any clearification on this would realy be appreciated!
Upvotes: 1
Views: 233
Reputation: 3854
for the first question, the Dinner.cs
file contains a partial of the Dinner
class along with some validation attributes on a buddy class. It's perfectly sane, IMHO, to put this file into the Model
folder, since it's actually part of the solution's model.
for your second question, the PaginatedList
is kind of a data structure which allows you to view a certain "page" of your data (a fixed set of elements) at a time. I don't really see it being a ViewModel
, a "helper" is exactly what it is.
One more thing I would like to add is, if you have some ViewModels that you pass in to your views instead of the actual model classes, or because you have a specific set of data elements to pass, I think it would be reasonable to have a separate ViewModel
folder for that.
Hope this helps :)
Upvotes: 1
Reputation: 941
Sure, your thinking is right about this. NerdDinner is made just for concept-presentation purposes and doesn't really pretends to all the best practices. It becomes more and more obvious as your own project grows. You will have your domain entities/services/repositories in separate folder, then separate project, then possibly separate solution. You will find yourself renamed this folder to ViewModels
to make it more obvious for other people working on project.
PaginatedList can be a ViewModel and contain data related to pagination. Then it can be put to ViewModels
folder. But I believe what you have in NerdDinner - is just a simple View helper to generate pagination markup. Moreover, helpers could be not that strict "View" or "ViewModel" - they can contain simple logic, they're somewhat in the middle :) between View and ViewModel. Also note that PaginatedList is more of a "framework" concern than of a "particular solution". So you can't place it to "Views" or "Models" folder amongst project-specific things. So "Helpers" is good enough for NerdDinner. In a real solution you'd better make it common, include it into your "framework" that is on top of MVC.
Upvotes: 1