Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collapse C# block within cshtml and save it

We have a bit big blocks of C# code within our cshtml files which must be presented in cshtml and nowhere else (obviously it's not a brilliant case but it's another question).

How we can collapse or hide these blocks of code in order to let our designers work more smoothly? We also want to hide these blocks of code during the demos of the progress with markup.

The real issue is that we also must save the visual representation into SVN.

Is there any native VS 2010 functionality for this or plugin? Maybe there is an opportunity to use "partial" cshtml pages where all the markup will be in one file and all C# code will be in another?

Unfortunately VS isn't going to collapse C# blocks of code within #region directive in such files.

Ultimately there is a similar question Regions In ASP.NET Views? but it gives no answer on how to save the collapsed representation when "Collapse Tag" context menu action item was used.

like image 829
xenn_33 Avatar asked Aug 26 '11 07:08

xenn_33


People also ask

What does OMP collapse do?

COLLAPSE: Specifies how many loops in a nested loop should be collapsed into one large iteration space and divided according to the schedule clause. The sequential execution of the iterations in all associated loops determines the order of the iterations in the collapsed iteration space.

What collapse means?

1 : to fall or shrink together abruptly and completely : fall into a jumbled or flattened mass through the force of external pressure a blood vessel that collapsed. 2 : to break down completely : disintegrate … his case had collapsed in a mass of legal wreckage …—

How do you use collapse?

Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element.

What is collapse in HTML?

collapse class indicates a collapsible element (a <div> in our example); this is the content that will be shown or hidden with a click of a button. To control (show/hide) the collapsible content, add the data-toggle="collapse" attribute to an <a> or a <button> element.


2 Answers

Try using Visual Studio's collapse functionality. By default I believe the keys are:

[Ctrl+M,Ctrl+H] to hide an arbitrary selection, and
[Ctrl+M,Ctrl+U] to unhide the same ( while collapsed ).

This should allow you to temporarily hide any code. More details available on MSDN

Is this what you were looking for?

Having read a little further you wish to save them collapsed, and apparently .cshtml doesn't support #regions. I guess a hacky solution might be the old:

@if(false){
    <div>
        <!--/*{your long code}*/-->
    </div>
}

Or something to that effect, but you get the idea :)

like image 140
Joebone Avatar answered Oct 05 '22 20:10

Joebone


Just select your code, right click and select Collapse Tag

like image 26
dohaivu Avatar answered Oct 05 '22 19:10

dohaivu