2

Is there an easy way to comment out a loop which renders some html and has inline html without deleting anything? I am copying and pasting some code from another project to rebuild a new public front end from a working internal backend.

Below is an example of a sitation in which it would be nice...in asp.net MVC 2

        <% 
       List<VehicleBodyTypeListItem> lstBodyTypes = (List<VehicleBodyTypeListItem>)ViewData["ddBodyType"];
       foreach (VehicleBodyTypeListItem bodyType in lstBodyTypes)
   {
      %>
      <a href="<%= Url.Action( "Search", new { BodyTypeID=bodyType.BodyTypeID, BodyType= Url.Encode( Html.WebLinkify( bodyType.BodyType))}) + (string)ViewData["httpCriteria"] %>">
        <%= Html.Encode( String.Format( "{0} ({1})", bodyType.BodyType, bodyType.Count.ToString()))  %>        </a>
        <br />
      <%
   }
   %>

I have not completed the method that populates this list yet, and have about 5 more like it further down the page.

1
  • AFAIK /* ... */ should work. You may have to apply some single-line comment delims after each of your <%= tags. Commented Feb 11, 2011 at 18:43

3 Answers 3

7

The keyboard shortcut is, if you select the section you want commented out is: CTRL + K + C will comment out code. CTRL + K + U will uncomment the code.

Sign up to request clarification or add additional context in comments.

Comments

7

Comment a block of code by enclosing it in @* and *@

Comments

0

Do you mean adding comments to the code. If so you just need to add //. Like here:

            <% 
       List<VehicleBodyTypeListItem> lstBodyTypes = (List<VehicleBodyTypeListItem>)ViewData["ddBodyType"];
       foreach (VehicleBodyTypeListItem bodyType in lstBodyTypes) // Here there's a comment
   {
      %>
      <a href="<%= Url.Action( "Search", new { BodyTypeID=bodyType.BodyTypeID, BodyType= Url.Encode( Html.WebLinkify( bodyType.BodyType))}) + (string)ViewData["httpCriteria"] %>">
        <%= Html.Encode( String.Format( "{0} ({1})", bodyType.BodyType, bodyType.Count.ToString()))  %>        </a>
        <br />
      <%
   }
   %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.