The following code will generate a link to the page I want to get to.
<%= Html.ActionLink(image.Title, image.Id.ToString(), "Image") %>
The following code will cause the correct url to be rendered on the page.
<%= Url.Action("Index", "Image", new { id = image.Id })%>
But when I try to use it in javascript it fails. (with some strange error about page inheritance)
<div onclick="window.location = '<%= Url.Action("Index", "Image", new { id = image.Id })%>'">
...
</div>
Should the above code work? What is the correct way to generate the javascript attempted above?
Update There error I get is
Views\Home\Index.aspx.cs(9): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
Looks like it indicates a bigger problem.
Fixed Thanks for your help, the code contained a div with runat="server"
. When I removed this it runs OK. This maybe because there is no form with runat="server"
but I would expect a different error for that.
As this question doesn't seem meaningful should I delete it?