I’m writing a wep application in which I’m using the Razor syntax here and there. (It’s build on the CMS Umbraco).
What I want to do is to call a method when a link (or button or whatever) is clicked. Something like this:
<a id="anchorId" class="AnchorClass" href="#"
onclick="@ClassName.Methodname(var1 v, var2 v)">
LinkText</a>
Problem is that Razor wants to execute this on page load and won’t wait for my click.
Does anyone know of a way to solve this?
- I tried load a new .cshtml into an invisible div via javascript, but that didn’t work.
- This is not an MVC application.
Thank you
You’re trying to mix server-side code with Javascript.
That won’t work.
You need to make the link point to a different server-side page that executes your code.
Alternatively, you could use Javascript to send an AJAX request to a different server-side page that executes your code.