45

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 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

BlackTigerX
  • 6,006
  • 7
  • 38
  • 48
  • This question violates a lot of FAQ guidelines. SO isn't the place to create a poll. Use what you and your team are comfortable with and can agree on. Naming conventions don't make a successful system. – John Farrell Mar 22 '11 at 02:58
  • 27
    @jfar "Naming conventions don't make a successful system.". No, they make successful teamwork, which make successful sytems – BlackTigerX Mar 22 '11 at 03:29
  • 1
    I said use what you and your team are comfortable with but it really doesn't matter what the convention is. - See I've been a part of too many projects where "style guides" just forced everybody to code in a style they weren't comfortable with. A good team is when you can identify Bobby's or Jimmy's little idiosyncrasies and can code perfectly fine with whatever quirks they use. Some guys feel comfortable and productive using var and some hate it. Ever try writing with your left hand? Thats how I feel when I have to conform to a particular style. – John Farrell Mar 22 '11 at 04:43
  • 13
    conventions matter to me (and a lot of people), I always try to use the standard, or the "unofficial standard", precisely because I don't like forcing my own preferences on the team – BlackTigerX Mar 22 '11 at 14:51
  • 4
    Conventions are good because when you move to another team (or workplace) you'll immediately recognise what the new team has been doing. We need more conventions in our line of business! – RickardN Feb 22 '13 at 07:39
  • Possible duplicate of [Naming Conventions For Partial Class Files](https://stackoverflow.com/questions/1478610/naming-conventions-for-partial-class-files) – cOborski Jul 15 '19 at 18:21

3 Answers3

47

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.

Community
  • 1
  • 1
Mike Brind
  • 28,238
  • 6
  • 56
  • 88
0

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.

Max Toro
  • 28,282
  • 11
  • 76
  • 114
-1

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?

Lance Fisher
  • 25,684
  • 22
  • 96
  • 122