ASP.NET MVC 3 Beta: Razor views support comments now

Sometimes we need server-side comments in ASP.NET MVC views. New version of Razor view engine supports comments in views and in this posting I will show you example of view with multiline comments.

I will use the view from my ASP.NET MVC charts caching example and add one multiline comment to this view. Note that comments are put between @* and *@ marks.

@{
    View.Title =
"Home Page"
;
}
 

<h2>@View.Message</h2
>
<
p>
    @*
 
        Charts area
        -----------
        1. cached for 10 minutes by default
        2. cached for 180 minutes
   
*@
   
<img src="/Home/MyChart" />
    <img src="/Home/MyCachedChart" 
/>
</
p
>

NB! This is only example. Don’t write long stories to the comments of your views. Add comments only if it is necessary and if it helps UI developers to communicate better with the presentation layer or model.

Gunnar Peipman

Gunnar Peipman is ASP.NET, Azure and SharePoint fan, Estonian Microsoft user group leader, blogger, conference speaker, teacher, and tech maniac. Since 2008 he is Microsoft MVP specialized on ASP.NET.

    3 thoughts on “ASP.NET MVC 3 Beta: Razor views support comments now

    • October 25, 2010 at 12:52 pm
      Permalink

      it supported until Beta not official but worked with

      @// comment

      we’re very for this loss :(

    • December 10, 2010 at 8:35 pm
      Permalink

      I’ve been visiting your blog for a while now and I always find a gem in your new posts. Thanks for sharing.

    Leave a Reply

    Your email address will not be published. Required fields are marked *