Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 471
Velter Avatar asked Mar 22 '11 14:03

Velter


People also ask

How do I add a region in Cshtml?

html or . cshtml code editor, type region , then press Tab key.

What are areas in ASP.NET MVC?

Area allows us to partition the large application into smaller units where each unit contains a separate MVC folder structure, same as the default MVC folder structure. For example, a large enterprise application may have different modules like admin, finance, HR, marketing, etc.

What are areas in asp net core?

Areas are an ASP.NET feature used to organize related functionality into a group as a separate namespace (for routing) and folder structure (for views). Using areas creates a hierarchy for the purpose of routing by adding another route parameter, area , to controller and action or a Razor Page page .

How can add Cshtml file in ASP.NET MVC?

Right click the Views\HelloWorld folder and click Add, then click MVC 5 View Page with Layout (Razor). In the Specify Name for Item dialog box, enter Index, and then click OK. In the Select a Layout Page dialog, accept the default _Layout. cshtml and click OK.


1 Answers

This works in Visual Studio 2015 and above (thanks to @dotnetN00b for the sample in the comments section):

<!-- #region Test -->  code here  <!-- #endregion --> 
like image 82
Mustafa Çakıroğlu Avatar answered Sep 28 '22 09:09

Mustafa Çakıroğlu