I accidentally left the presentation model class file in Razor Pages with the extension .cs instead of .cshtml.cs. On a simple example, it works. Are there any pitfalls to this solution other than breaking the naming convention. And why did Microsoft make such an agreement? After all, .cs looks much cleaner and more practical than .cshtml.cs.
Another value for the *.cshtml.cs
naming convention is that it provides insight into the contents of the class file, in much the same way that JavaScript files are named.
Using the three.js project as an example, the main file has multiple versions:
three.module.js
three.module.min.js
three.js
(deprecated in v150+)three.min.js
(deprecated in v150+)All of these files are JavaScript files with the extension .js
but the additional naming "extensions" provide clues for the content of the file: three.module.js
is the ES Module version of the core three.js
project. three.module.min.js
is the minified version of the ES Module build. three.min.js
was the minified version of the original pre-ES Module version three.js
file.
A /Pages
folder in a Razor project can have the following:
The naming convention of Index.cshtml.cs
provides insight that this class file has a page model declaration and is associated with a Razor view file.
The file Index.cs
, if in the same folder as Index.cshtml
and Index.cshtml.cs
can have any content like a class model declaration used in Index.cshtml.cs
. The file could be named this way to associate Index.cs
with the Razor page.