In a Razor Pages view (no "@page" attribute; just a cshtml file), I'm attempting to render an anchor tag. I don't want to employ the tag helper, I just want it to render like this:
<a href="javascript:void(0)" onclick="javascriptFunctionCall(1)" class="page-link"><i class="fas fa-fast-backward"></i></a>
The view renders with no error message, but the "href" and "onclick" attributes inside the anchor tag simply do not render. The "class" attribute does render. If I add other attributes to the tag they also render. I'm using fontawesome icons, and they render properly. But the "href" and "onclick" attributes do not render.
For the "href" attribute, if I change the value to "#", it renders. Obviously, something in the RazorPages rendering engine is saying "I will not render this" if the attribute contains javascript.
This apparently only happens in a view. I notice that I try to render the same element on a page (has the @page attribute) it renders fine.
The view itself is rendered when a user clicks a button, which makes a fetch call, which hits a server-side method that renders the view like this:
return Partial("_MyViewName", myModel);
Is there any way to render static values in the href and onclick attributes in an anchor tag in a Razor view?
I was inadvertently removing the javascript myself because, in javascript, I was passing the value returned from the server through the DOMPurify library (to guard against a javascript injection attack). This was very stupid of me, but special thank you to @KingKing for forcing me to figure it out.