Why do I need an underscore for partial views in asp.net mvc

后端 未结 3 1534
眼角桃花
眼角桃花 2021-02-12 09:37

Just to distinguish between a view used inside a dialog or used in a foreach loop (customer details) ?

3条回答
  •  后悔当初
    2021-02-12 10:21

    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.

    Besides that, I find it very helpful to use this convention to differentiate between full views and partial ones.

提交回复
热议问题