14

In visual studio 2010 markup in MVC3 and ASPX pages was collapsible (by closing tag) however it does not seem to be working in visual studio 2012. Anyone know how to get it working? I cant find it in the options...

:-)

Exitos
  • 29,230
  • 38
  • 123
  • 178

4 Answers4

32

This worked for me in Visual Studio 2013:

<!-- #region Targets -->

<h1>Targets</h1>

<fieldset>

...

</fieldset>

<!-- #endregion -->
Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
  • @MatheusMiranda Taken from a forum post "under **Tools, Options, Text Editor, C#, Advanced** the last option 'Collapse #regions when collapsing to definitions' is not checked. Checking it fixed this issue. It used to be the default" – mbomb007 Dec 12 '17 at 16:27
  • 1
    Just an FYI - The simple method above works in Visual Studio 2022 as well (an MVC5 project in this case) – IdahoB Oct 27 '22 at 21:20
1

This looks like it has already been answered here: Collapse C# block within cshtml and save it However, if you're after automatic collapsing of Razor sections in your cshtml, then it looks like you're out of luck. The usual CTRL-M,M and CTRL-M+CTRL-T chorded shortcuts will work only on the html which you will see have the familiar +/- collapsing indicators on the margin.

Community
  • 1
  • 1
John Kelleher
  • 411
  • 5
  • 7
1

Seems to work in Visual Studio 2012

 @* <!-- #region Some Name --> *@
 @* <!-- #endregion --> *@
Leon
  • 616
  • 1
  • 6
  • 10
  • The question refers to Visual Studio 2012. See question. – Leon Dec 13 '17 at 16:23
  • Does the most-voted solution also work? If so, then it's a better solution – mbomb007 Dec 13 '17 at 19:05
  • I no longer have VS2012 but at the time the excepted answer did not work in VS2012. Web essentials did not support that syntax until WE 2013 http://vswebessentials.com/features/html#region What I proposed was a work around that did work in VS2012. – Leon Dec 14 '17 at 09:52
0
  1. Highlight your code block.
  2. Right-click
  3. Select "Collapse Tag"
RedAces
  • 319
  • 1
  • 3
  • 16
  • 3
    Can we save the collapsed region so that if we restart visual studio, it remembers where we added our own custom tags/outlines/regions? Ctrl+M+H makes a custom collapsible region of the highlighted text but does not remember it on VS restart. – zeppelin Nov 27 '14 at 09:57