Question

When I create a new ASP.NET MVC project two files with underscore are created: Views/_ViewStart.cshtml and Views/Shared/_Layout.cshtml. What does underscore mean?

Was it helpful?

Solution

Mike Brind has put this nicely in the question Why does Razor _layout.cshtml have a leading underscore in file name?:

Since layout pages in Web Pages are not intended to be served directly, they are prefixed with the underscore. And the Web Pages framework has been configured not to allow files with leading underscores in their names from being requested directly.

In MVC, I use this convention to name partial views with a leading underscore to differentiate between full views and partial ones.

OTHER TIPS

It is a naming convention for "included" views (master pages, partial views etc or any views that would not render stand-alone) - nothing magical, just a convention - although I seem to remember the underscore may be significant in WebPages, but certainly not in MVC.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top