Reputation: 15771
I know I will probably get a mixed opinion on this, but I was wondering if there were and "Best Practices" for model naming conventions.
I have a rather large application and I have adopted the following model naming convention:
I was thinking of the following as well:
Which do you prefer, and why?
Do you think it really matters?
Upvotes: 20
Views: 23859
Reputation: 12577
To pull out Hightmaston's comment into a formal answer for clarity.
A logical template to follow would be:
{Controller}{ViewName}ViewModel
This encourages better file organization at scale, and reduces the number of Intellisense "hits".
A simple example might be as follows:
CategoryIndexViewModel
For brevity you may also consider:
CategoryIndexModel
Upvotes: 8
Reputation: 53183
It doesn't matter. You should name things in a consistent, logical, and straightforward way. Basically, just pick something that makes sense and makes you most productive. Consider how your naming convention would work with IntelliSense.
You might also want to consider how easy your code will be to maintain a year from now.
Upvotes: 10
Reputation:
In theory CategoryViewModel, CategoryAddModel and CategoryEditModel will contain the same properties, so there is little point tripling the number of view models you have in your UI. Just CategoryModel should suffice. It's the type of HTTP requests being received by your controller which defines whether it's a GET or POST operation. The model used to populate a view for a GET, or capture form data for a POST will be the same type either way.
Upvotes: 2
Reputation: 972
I prefer like {ViewName}{Controller}ViewModel
. I also remove Models
folder, instead I put view models in ViewModels
folder. That makes more sense to me.
eg. AddCategoryViewModel
Upvotes: 18