Deleting comments in MVC view - html

I want to include html-comment in my view (mvc3-app):
<!-- comment -->
but Razor delete this code on render page. I try to use
#Html.Raw ("<!-- Comment -->")
but without result.
p.s. i need to use comment for google-adsense targeting.
edited:
Add Html.Raw result
Left side -> VS code. Right side -> FireBug

Razor view engine deletes from resulting markup 'server-side' comments within a #* ... *# block, but it keeps 'client-side' comments (i.e. HTML comments) - <!-- ... -->.
They can be deleted by your browser markup viewer. Try to open full page markup or view it in another tool.

Related

Can we auto-expand an HTML 'details' when a hyperlink points to it?

I am creating a page with language information. Since it is extremely long, I collapse each language with details/summary tags and have them in alphabetic sections with each initial letter also a collapsed details. Currently, each language is coded like
<details>
<summary id="am"><b>am — Amharic</b></summary>
<p><img src="/wp-content/uploads/2018/05/GBV-Amharic-150.jpg"/>About 22 million native speakers, … [more info]</p><br clear="all"/>
</details>
If I put a link elsewhere like http://domain.TLD/path/#am, I'd like to take the user to that page, scroll to that section, and expand the details. If that's possible, do I have the wrong syntax for one or both sides? It is not working now—nothing expands and it goes to the top of the page as if the # were not there. But the address field shows the full URI of the link, #id included.
"path/" is interpreted by Wordpress and/or a Wordpress-generated .htaccess, so perhaps that somehow prevents it working correctly.
You have the correct syntax for directing a user to an element with the id "am."
You can check the URL the browser used to display the page with jQuery. For your example if a link sent a user to http://domain.TLD/path/#am the following code would trigger if the browser contained "path/#am" as part of the URL.
jQuery(document).ready(function($) {
if(window.location.href.indexOf("path/#am")){
/* do something to the element in jQuery -- likely apply a class.
*/
}
There are many animation and scrolling libraries related to jQuery as well.

JSP comment is called hide comment whereas html comment is called output comment

I'm preparing for an interview so while reading some questions I found that the "JSP comment is called hide comment whereas html comment is called output comment". And the answer says that if we try to view source in JSP, the comments will not be shown whereas in HTML, it will be shown.
But I'm able to see the comment in the view source section.
Can anybody clear this doubt?
Thanks in advance.
There are two types of comments are allowed in the JSP. These are hidden and output comments. A hidden comments does not appear in the generated output in the html, while output comments appear in the generated output.
Example of hidden comment:
<%-- This is hidden comment --%>
Example of output comment:
<!-- This is output comment -->
Well, technically if you use a typical JSP comments , like
<%-- This is a comment --%>
, and do a veiw source , you wont see it on the client side , if you however do an HTML style comment
<!-- This is a comment -->
, you can see view source and see that on the client side . needless to say , you can comment like the normal java style too , inside the jsp tags . hope it helps .
Html comments don't prevent jsp from evaluating values
<!-- <%! int x = 0; %> -->
This line will declare x variable.

MVC4 using sections to include javascript

I am working on an asp.net MVC4 application. In my layout page, I have the following code
#RenderSection("page-specific", required: false)
and In my view which uses the above layout, I have
#section page-specific{
<script src="~/Scripts/page-specific.js" type="text/javascript"></script>
}
When I run my application, it gives me the following error
Sections cannot be empty. The "#section" keyword must be followed by a block of markup surrounded by "{}"
But all I want to do is include some page specific styles and javascript. I dont want to include any HTML markup in this particular section. How can I do this while avoiding the empty section error?
Try naming it pageSpecific. I haven't tried using a hyphen in a section name before, but I have a feeling mvc might not like that.

How to add block comments in HTML? [duplicate]

I have some HTML code on a page that I don't want to erase, but make inactive for the short term. How can I make the browser ignore parts of the page in the same way the // works in some programming languages?
Behold HTML comments:
<!-- comment -->
http://www.w3.org/TR/html401/intro/sgmltut.html#idx-HTML
The proper way to delete code without deleting it, of course, is to use version control, which enables you to resurrect old code from the past. Don't get into the habit of accumulating commented-out code in your pages, it's no fun. :)
HTML Comments:
<!-- <div> This div will not show </div> -->
See Reference
CSS Comments:
/* This style will not apply */
See Reference
JavaScript Comments:
// This single line JavaScript code will not execute
OR
/*
The whole block of JavaScript code will not execute
*/
See Reference
To comment block with nested comments: substitute inner (block) comments from "--" to "++"
<!-- *********************************************************************
* IMPORTANT: To uncomment section
* sub inner comments "++" -> "--" & remove this comment
*********************************************************************
<head>
<title>My document's title</title> <++! My document's title ++>
<link rel=stylesheet href="mydoc.css" type="text/css">
</head>
<body>
<++! My document's important HTML stuff ++>
...
...
...
</body>
*********************************************************************
* IMPORTANT: To uncomment section
* sub inner comments "++" -> "--" & remove this comment
*********************************************************************
-->
Thus, the outer most comment ignores all "invalid" inner (block) comments.
Just create a multi-line comment around it. When you want it back, just erase the comment tags.
For example, <!-- Stuff to comment out or make inactive -->
Use:
<!-- This is a comment for an HTML page and it will not display in the browser -->
For more information, I think 3 On SGML and HTML may help you.
If you are using Eclipse then the keyboard shortcut is Ctrl + Shift + / to add a group of code. To make a comment line or select the code, right click -> Source -> Add Block Comment.
To remove the block comment, Ctrl + Shift + \ or right click -> Source -> Remove Block comment.
Reason of comments:
Comment out elements temporarily rather than removing them, especially if they've been left unfinished.
Write notes or reminders to yourself inside your actual HTML documents.
Create notes for other scripting languages like JavaScript which requires them
HTML Comments
<!-- Everything is invisible -->

Are JSP expressions evaluated inside HTML comments of a JSP page?

Are JSP expressions evaluated inside HTML comments of a JSP page?
i.e What would server output in this case?
<!--
Jeremy <%="Flowers"%>
-->
Will the expression be resolved or will it remain as an expression in the HTML comment
a)
<!--
Jeremy <%="Flowers"%>
-->
or b)
<!--
Jeremy Flowers
-->
Yes, the expressions will be resolved. The JSP page doesn't even know it is writing in HTML format, so it doesn't interpret anything HTML-specific.
You can also write plain text using JSP, or JSON, or whatever you like.
Those are html comments, not jsp comments. So, all jsp code inside is still evaluated.
There's also jsp-specific way to comment content: <%-– ... -–%>. Content inside won't be evaluated by the server and won't be passed to the browser. So, it acts as html comment too.
you can even use HTML comments to hide evaluated results from jsp expressions partially when the page is rendered to the browser.
e.g.
`${empty requestScope.errors? "" : "<p id='errors'>Error(s)!
<ul>"}
<!--${requestScope.errors.stream().map(x -> "-->
<li>"x"</li>
<!--").toList()}-->
${empty requestScope.errors? "" : "</ul></p>"}`
the local variable x from requestScope.errors.stream().map(x->) is still evaluated and passed to <li>"+=x+="</li>
output:
` Error(s)!
Product must have a nameProduct must have a price`
if the expressions are not in HTML comment tag, the "[]" symbol will appear due to .toList()
output without HTML tag:
`Error(s)!
[Product must have a nameProduct must have a price]`