Search code examples
c#asp.net-mvcconventionsconvention-over-configur

What is wrong with placing models in a folder other than Models?


I'm a new learner of ASP.NET MVC. I looked through few books and code samples. While I learn I came up with the below question and cannot clearly understand the point below.

Most books explain that placing Models in Models folder is a Convention over Configuration. They also state that ASP.NET MVC Framework assumes developers to put Models in that folder. However, most code samples and many other developers place Models in a folder other than Models, such as ViewModels in a separate class library project (i.e. Services Project).

Is there any difference of these two ways? Is there anything ASP.NET MVC does with models if we place them in Models folder? What is good and bad about them? How do you do for your projects?


Solution

  • Most books explain that placing Models in Models folder is a Convention over Configuration. They also state that ASP.NET MVC Framework assumes developers to put Models in that folder.

    This is wrong. The only time asp.net-mvc uses folder structure and needs its configuration (explicitly or by convention) is when finding Views. Controllers have convention to end with suffix "Controller" and Models do not have any. You can feel free to place models where ever you like.