开发者

Naming convention to differentiate partial views from normal views

开发者 https://www.devze.com 2023-02-19 07:10 出处:网络
Is there any unofficial standard naming convention for partial views? I\'ve seen someone suggested prefixing with \"_\", others postfixing with \"Partial\", I know the question is subjective, but sinc

Is there any unofficial standard naming convention for partial views? I've seen someone suggested prefixing with "_", others postfixing with "Partial", I know the question is subjective, but since there is no official guideline, I'd like to know what the majority here uses for naming their partial views. Perhaps the most voted answer开发者_StackOverflow中文版 WILL become the standard.

Update: I'm using ASP.NET MVC 3 with Razor as the view engine, in previous versions you didn't need a convention because you had the .ascx extension


If you look at WebMatrix, the convention is to prefix Razor files that are not meant to be served directly with a leading underscore. That includes partials and layout pages. Then if you look at MvcScaffolding, you can see that the default templates generate files using the same naming convention.

Read this for an explanation as to why that convention might be used.


Razor templates can be partially rendered, even if they use a layout page and have different sections. Unlike ASPX, Razor templates have a body. I don't see the need for a naming convention, it depends on how you use the template.


I used to use "p_" as a prefix when I was using .aspx files as partial views. I pretty much just use .ascx files for partial views now, and I don't find the need to give them either a prefix or a postfix. The .ascx serves that purpose, and Visual Studio assigns a different icon to .ascx fies.

What view engine are you using?

0

精彩评论

暂无评论...
验证码 换一张
取 消