Regions In ASP.NET Views?

I am making an ASP.NET MVC application with a shaving engine.
And I was wondering if the Regions could be used in the view.

something like:

#region blabla <p>@Model.Name</p> <p>...</p> #endregion 

This does not work. Is there an alternative?

+43
asp.net-mvc views asp.net-mvc-3 razor region
Mar 22 2018-11-22T00:
source share
10 answers

If you download Web essential 2013, you can use regions in both cshtml and javascript files.

Like this (thanks @dotnetN00b for the sample in the comments section):

 <!-- #region Test --> code here <!-- #endregion --> 
+67
Mar 28 '14 at 12:29
source share

Select the part to be converted to a region, then right-click and click CollapseTag

+49
Aug 24 '11 at 6:59 a.m.
source share

In Visual Studio, you can manually add a selection as follows:

To create or delete a folding area

  • Select the text you want to treat as a drop region.

  • To create a collapsible area, from the Edit menu, select Outline, and then Hide Selection.

The editor turns the selection into a region, collapses it, and displays a field with an ellipsis (...) to indicate that the region contains a folded region. You can hold the mouse pointer over the field to see its contents.

  1. To remove a replacement region, collapse it, and then click on it to select it.

  2. From the Edit menu, select Outline and click Stop Hiding.

To collapse and expand a single area

  • To collapse a region, click the minus sign (-) in the editor field.

  • To expand a collapsed area, click the plus sign (+) in the box.

To collapse and expand all areas

From the Edit menu, select Outline, and then Switch All. Describing.

From MSDN

But this is not very practical.

For HTML, you can manually edit the schema parameter for each tag in text editor options:

enter image description here

enter image description here

The minimum value of the minimum rows is 1. Effective.

Additional MSDN Information

+12
May 12 '13 at 9:59
source share

No, AFAIK cannot use regions in a view. You can use partial elements to group view areas into reusable partial views.

See newer answer ; It works and achieves the desired effect.

+11
Mar 22 2018-11-22T00:
source share

I do not have the "CollapseTag" option in my context menu. I usually do the following:

  • Select the text.
  • Goto Edit -> Outlining -> Hide Selection.

or

use Ctrl + M, Ctrl + H

I am using Microsoft Visual Studio Pro 2013.

+9
Apr 08 '15 at 10:39
source share

Divs are collapsible, so you can always use them with some id property in the form of facial areas.

 <div id="BLABLA">...</div> 
+3
Mar 22 '11 at 16:52
source share

You can use Masterpages with RenderPartial or RenderAction to make your views RenderAction . Both have their places.

+3
Mar 22 '11 at 18:35
source share

regions sort work in looks for me, I can identify the area, but it will not collapse. If you use the @Artur method to use the Collapse Tag, you are very much there! :)

+3
May 2 '12 at 9:39
source share

In Vs2015 and Resharper, enter "region" on the html or cshtml page, then press the Tab key. This code snippet is #region snippet.

 <!-- #region name --> //Your html or cshtml codes <!-- #endregion --> 
+3
Nov 02 '15 at 8:29
source share

Remember that using scopes can cause problems in views - although they are syntactically justified, often the notation between code and HTML / SCRIPT becomes "confused", leading to unpredictable behavior.

DIVs are by far the โ€œbestโ€ solution, especially if additional DIV files provide more flexibility when changing CSS styles later.

If you need a lot of regions, then think about how to update your code.

0
Apr 26 '13 at 13:09 on
source share



All Articles