You must Sign In to post a response.
  • Category: ASP.NET

    _Naming convention in shared files in MVC

    Hi All,
    I faced a interview question like
    why the shared folder .cshtml files name starting with _ symbol in MVC applications?

    please share the answers..

    Thanks in advance
  • #768603
    Hi,

    There aren't really any special properties regarding underscores at least in relation to View Names within MVC. The usage of underscores is a common naming convention as you mentioned for pages that are going to be reused within a single application (this is why you might see many of them within a "Shared" folder) but it is not required by any means.

    As the link that you provided mentions and this is more relevant outside of MVC (due to routing) but the usage of an underscore actually should prevent a user from navigating directly to a page (ie localhost/_YourPage.cshtml) however within MVC, you should be completely safe since pages are not accessed directly like that.

    We see many things like following in MVC application,
    _viewstart
    _Layout
    _LogOnPartial

    Thanks,
    Mani


  • Sign In to post your comments