I have javascript that changes an image on a mouseover event:
<img src="~/Images/image1.png" onmouseover="this.src='~/Images/image2.png'" onmouseout="this.src='~/Images/image1.png'" />
The initial image is correct, but the mouse over image isn't found. I now undertand that the tilde path (i.e., "~/") can't get resolved to the application folder (e.g., /myapp/images/image2.png) in the javascript string.
So I'm trying to use ResolveClientURL() to change the tilde path server-side:
onmouseover="this.src='" + this.Page.ResolveClientURL("~/Images/image2.png") + "'"
But that generates a "Cannot perform runtime binding on a null reference" error.
So I wrote the following in my cshtml file (not involving any javascript) and it, too, generates the null reference error.
@{
var tildePath = "~/Images/image1.png";
var newPath ...
Go to the complete details ...