Regions In ASP.NET Views?
I am making an ASP.NET MVC application with the razor engine.
And I was wondering if it's possible to use Regions in a view.
something like:
#region blabla
<p>@Model.Name</p>
<p>...</p>
#endregion
This does not work. Is there an alternative?
This works in Visual Studio 2015 and above
(thanks to @dotnetN00b
for the sample in the comments section):
<!-- #region Test -->
code here
<!-- #endregion -->
Select the part which needs to be converted to region, then right click and press CollapseTag
In Visual Studio (2015 and above) .html or .cshtml code editor, type region
, then press Tab
key.This implements #region
snippet code like below:
<!-- #region name -->
//Your html or cshtml codes
<!-- #endregion -->.
In Visual Studio, you can manually add outlined region like this :
To create or remove a collapsible region
Select the text you want to treat as a collapsible region.
To create a collapsible region, on the Edit menu, point to Outlining, and then click Hide Selection.
The editor turns the selection into a region, collapses it, and displays a box with an ellipsis (...) to indicate that the area contains a collapsed area. You can hold the mouse pointer over the box to see its contents.
To remove a collapsible region, collapse it, and then click it to select it.
On the Edit menu, point to Outlining, and then click Stop Hiding Current.
To collapse and expand a single region
To collapse a region, click the minus sign (-) in the margin of the editor.
To expand a collapsed region, click the plus sign (+) in the margin.
To collapse and expand all regions
On the Edit menu, point to Outlining, and then click Toggle All Outlining.
From MSDN
But that's not really practical.
For HTML you can manually edit the outline option for each tags in the text editors options :
Minimum value of minimum lines is 1 to be effective.
More info on MSDN