为什么剃须刀_layout.cshtml在文件名前面的下划线? [英] Why does Razor _layout.cshtml have a leading underscore in file name?

查看:116
本文介绍了为什么剃须刀_layout.cshtml在文件名前面的下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在默认的ASP.NET MVC 3项目,布局和放大器;部分CSHTML文件启动以下划线

In the default ASP.NET MVC 3 project, layout & partial cshtml files start with an underscore


  • _viewstart

  • _layout

  • _LogOnPartial

  • _viewstart
  • _Layout
  • _LogOnPartial

这是什么意思公约,并用于什么呢?我是否需要遵守这个约定?

What is this convention mean, and what is used for? Do I need to follow this convention?

该框架是否给予一定的特殊意义以下划线开头的 .cshtml 文件?

Does the framework give some special meaning to a .cshtml file that begins with an underscore?

推荐答案

剃刀是为ASP.NET网页(WebMatrix中),它不具有相同的排序建在有关文件夹视图和路由,你得到的保护开发在MVC。由于网页布局页不打算直接送达,它们与下划线pfixed $ P $。而网页框架已配置为不被直​​接要求允许与在其名称中前导下划线文件。在网页的其他.cshtml文件通常需要以浏览。他们的.asp或.php文件的等价物。

Razor was developed for ASP.NET Web Pages (WebMatrix), which doesn't have the same sort of protection built in regarding Views folders and Routing that you get within MVC. 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. Other .cshtml files within Web Pages generally need to be browsable. They are the equivalent of .asp or .php files.

ASP.NET小组都表示,网页是ASP.NET开发中的一个出发点,这应该引起移植到MVC的时间(对于那些想要继续前进)。的一部分意味着它应该尽可能容易地从网页到MVC迁移。因此,它是有道理的结转命名网页到MVC剃刀文件内建立约定。

The ASP.NET team have stated that Web Pages is a starting point within ASP.NET development, which should lead to migration to MVC in time (for those that want to move on). Part of that means that it should be as easy as possible to migrate from Web Pages to MVC. Consequently, it makes sense to carry over naming conventions established within Web Pages to MVC Razor files.

所以 技术原因$ P $用下划线pfixing文件名 - 它仅仅是不相关的MVC

So there is a technical reason for prefixing the file names with an underscore - it just isn't relevant to MVC.

这篇关于为什么剃须刀_layout.cshtml在文件名前面的下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆