Home/MVC/Server-Side Comment in MVC

Server-Side Comment in MVC

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


Example: Server Side Comment

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


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

Leave a Reply