In this post we are going to discuss about new feature in mvc, that is server-side comment.

What is Client side comments?

(<!– –>) it is a Comment which is support by HTML. It main purpose to prevent a browser from running or displaying the code/content in the application.

What is Server Side Comments?

In ASP.NET MVC supports a server-side comment which make code/content completely disable in the page.

ASP.NET Web Forms supports a server-side comment that you can use to completely disable content/code within a page. Using this compiler completely ignore everything within the @*– –*@ blocks at parse time, and removes the content completely when assembling the page in the browser(in simple it won’t show the content/code in the browser).ย So the contents wasnโ€™t there at the page while loading in browser.

Syntax for Server side comment :

MVC Razor : @*– –*@
ASP WebForm : <%– –%>

Why Server Side Comments is needed?

The problem with using Client side comments approach, is that the content contained within the comment in our application is still sent to the client from the server unnecessarily.Then the server-side code within the comment will still execute. This will create extra load to the server. To overcome this scenario we moved to the server side comments

Example: Clientย Side Comment

Include <!–<h1>Bundling in dotnet-helpers.com</h1>–> in view/form, then the output will be

Server-side-Comments-dotnet-helpers.com-1

Example: Server Side Comment

Includeย @*<h1>Bundling in dotnet-helpers.com</h1>*@ in view/form, then the output will be

Server-side-Comments-dotnet-helpers.com-2

Note :

  • ย Inย Clientย Side Comment, the commented code/content will be loading to the browser side as shown in example above
  • ย Inย Serverย Side Comment, the commented code/content will not be load to the browser side as shown in example above